Logo Search packages:      
Sourcecode: blender version File versions

GHOST_C-api.cpp

/**
 * $Id: GHOST_C-api.cpp,v 1.4 2003/12/26 20:12:40 rwenzlaff Exp $
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version. The Blender
 * Foundation also sells licenses for use in proprietary software under
 * the Blender License.  See http://www.blender.org/BL/ for information
 * about this.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * The Original Code is: all of this file.
 *
 * Contributor(s): none yet.
 *
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
 */

/*

 * GHOST_C-Api.cpp
 *
 * C Api for GHOST
 *
 * Version: $Id: GHOST_C-api.cpp,v 1.4 2003/12/26 20:12:40 rwenzlaff Exp $
 */

#include <stdlib.h>

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#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"

#ifdef WIN32
#pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
#endif //WIN32


00059 GHOST_SystemHandle GHOST_CreateSystem(void)
{
      GHOST_ISystem::createSystem();
      GHOST_ISystem* system = GHOST_ISystem::getSystem();

      return (GHOST_SystemHandle)system;
}



00069 GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;

      return system->disposeSystem();
}


00077 GHOST_EventConsumerHandle GHOST_CreateEventConsumer(GHOST_EventCallbackProcPtr eventCallback, GHOST_TUserDataPtr userdata)
{
      return (GHOST_EventConsumerHandle) new GHOST_CallbackEventConsumer (eventCallback, userdata);
}


00083 GHOST_TSuccess GHOST_DisposeEventConsumer(GHOST_EventConsumerHandle consumerhandle)
{
      delete ((GHOST_CallbackEventConsumer*)consumerhandle);
      return GHOST_kSuccess;
}


00090 GHOST_TUns64 GHOST_GetMilliSeconds(GHOST_SystemHandle systemhandle)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;

      return system->getMilliSeconds();
}



00099 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);
}



00112 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);
}



00123 GHOST_TUns8 GHOST_GetNumDisplays(GHOST_SystemHandle systemhandle)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;

      return system->getNumDisplays();
}



00132 void GHOST_GetMainDisplayDimensions(GHOST_SystemHandle systemhandle,
                                                      GHOST_TUns32* width,
                                                      GHOST_TUns32* height)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
      
      system->getMainDisplayDimensions(*width, *height);
}



00143 GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
                                                        char* title,
                                                        GHOST_TInt32 left,
                                                        GHOST_TInt32 top,
                                                        GHOST_TUns32 width,
                                                        GHOST_TUns32 height,
                                                        GHOST_TWindowState state,
                                                        GHOST_TDrawingContextType type,
                                                        const int stereoVisual)
{
      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);
}

00165 GHOST_TUserDataPtr GHOST_GetWindowUserData(GHOST_WindowHandle windowhandle)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->getUserData();
}
00171 void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUserDataPtr userdata)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      window->setUserData(userdata);
}

00178 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);
}



00189 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);
}



00200 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;
}



00220 GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;

      return system->endFullScreen();
}



00229 int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;

      return (int) system->getFullScreen();
}



00238 int GHOST_ProcessEvents(GHOST_SystemHandle systemhandle, int waitForEvent)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
      
      return (int) system->processEvents(waitForEvent?true:false);
}



00247 int GHOST_DispatchEvents(GHOST_SystemHandle systemhandle)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
      
      return (int) system->dispatchEvents();
}


00255 GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle, GHOST_EventConsumerHandle consumerhandle)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
      
      return system->addEventConsumer((GHOST_CallbackEventConsumer*)consumerhandle);
}



00264 GHOST_TStandardCursor GHOST_GetCursorShape(GHOST_WindowHandle windowhandle)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->getCursorShape();
}



00273 GHOST_TSuccess GHOST_SetCursorShape(GHOST_WindowHandle windowhandle,
                                                      GHOST_TStandardCursor cursorshape)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->setCursorShape(cursorshape);
}

00281 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);
}

00292 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);
}



00310 int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return (int) window->getCursorVisibility();
}



00319 GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle,
                                                             int visible)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->setCursorVisibility(visible?true:false);
}



00329 GHOST_TSuccess GHOST_GetCursorPosition(GHOST_SystemHandle systemhandle,
                                                         GHOST_TInt32* x,
                                                         GHOST_TInt32* y)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
      
      return system->getCursorPosition(*x, *y);
}



00340 GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
                                                         GHOST_TInt32 x,
                                                         GHOST_TInt32 y)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
      
      return system->setCursorPosition(x, y);
}



00351 GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle,
                                                             GHOST_TModifierKeyMask mask,
                                                             int* isDown)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
      GHOST_TSuccess result;
      bool isdown;
      
      result = system->getModifierKeyState(mask, isdown);
      *isDown = (int) isdown;

      return result;
}



00367 GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle,
                                                      GHOST_TButtonMask mask,
                                                      int* isDown)
{
      GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
      GHOST_TSuccess result;
      bool isdown;
      
      result = system->getButtonState(mask, isdown);
      *isDown = (int) isdown;

      return result;
}



00383 GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle)
{
      GHOST_IEvent* event = (GHOST_IEvent*) eventhandle;
      
      return event->getType();
}



00392 GHOST_TUns64 GHOST_GetEventTime(GHOST_EventHandle eventhandle)
{
      GHOST_IEvent* event = (GHOST_IEvent*) eventhandle;

      return event->getTime();
}


00400 GHOST_WindowHandle GHOST_GetEventWindow(GHOST_EventHandle eventhandle)
{
      GHOST_IEvent* event = (GHOST_IEvent*) eventhandle;

      return (GHOST_WindowHandle) event->getWindow();
}


00408 GHOST_TEventDataPtr GHOST_GetEventData(GHOST_EventHandle eventhandle)
{
      GHOST_IEvent* event = (GHOST_IEvent*) eventhandle;
      
      return event->getData();
}



00417 GHOST_TimerProcPtr GHOST_GetTimerProc(GHOST_TimerTaskHandle timertaskhandle)
{
      GHOST_ITimerTask* timertask = (GHOST_ITimerTask*) timertaskhandle;
      
      return timertask->getTimerProc();
}



00426 void GHOST_SetTimerProc(GHOST_TimerTaskHandle timertaskhandle,
                                    GHOST_TimerProcPtr timerproc)
{
      GHOST_ITimerTask* timertask = (GHOST_ITimerTask*) timertaskhandle;
      
      timertask->setTimerProc(timerproc);
}



00436 GHOST_TUserDataPtr GHOST_GetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle)
{
      GHOST_ITimerTask* timertask = (GHOST_ITimerTask*) timertaskhandle;

      return timertask->getUserData();
}

      

00445 void GHOST_SetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle,
                                                GHOST_TUserDataPtr userdata)
{
      GHOST_ITimerTask* timertask = (GHOST_ITimerTask*) timertaskhandle;
      
      timertask->setUserData(userdata);
}



00455 int GHOST_GetValid(GHOST_WindowHandle windowhandle) 
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return (int) window->getValid();
}



00464 GHOST_TDrawingContextType GHOST_GetDrawingContextType(GHOST_WindowHandle windowhandle)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->getDrawingContextType();
}



00473 GHOST_TSuccess GHOST_SetDrawingContextType(GHOST_WindowHandle windowhandle,
                                                               GHOST_TDrawingContextType type)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->setDrawingContextType(type);
}



00483 void GHOST_SetTitle(GHOST_WindowHandle windowhandle,
                              char* title)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
      
      window->setTitle(title);
}


00492 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);
      strcpy(ctitle, title.Ptr());
            
      return ctitle;
}



00507 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;
}



00520 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;
}



00533 void GHOST_DisposeRectangle(GHOST_RectangleHandle rectanglehandle)
{
      delete (GHOST_Rect*) rectanglehandle;
}



00540 GHOST_TSuccess GHOST_SetClientWidth(GHOST_WindowHandle windowhandle,
                                                      GHOST_TUns32 width)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->setClientWidth(width);
}



00550 GHOST_TSuccess GHOST_SetClientHeight(GHOST_WindowHandle windowhandle,
                                                       GHOST_TUns32 height)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->setClientHeight(height);
}



00560 GHOST_TSuccess GHOST_SetClientSize(GHOST_WindowHandle windowhandle,
                                                   GHOST_TUns32 width,
                                                   GHOST_TUns32 height)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->setClientSize(width, height);
}



00571 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);
}



00584 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);
}



00597 GHOST_TWindowState GHOST_GetWindowState(GHOST_WindowHandle windowhandle)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->getState();
}



00606 GHOST_TSuccess GHOST_SetWindowState(GHOST_WindowHandle windowhandle,
                                                      GHOST_TWindowState state)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->setState(state);
}



00616 GHOST_TSuccess GHOST_SetWindowOrder(GHOST_WindowHandle windowhandle,
                                                      GHOST_TWindowOrder order)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
      
      return window->setOrder(order);
}



00626 GHOST_TSuccess GHOST_SwapWindowBuffers(GHOST_WindowHandle windowhandle)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->swapBuffers();
}



00635 GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandle)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
      
      return window->activateDrawingContext();
}



00644 GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle)
{
      GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;

      return window->invalidate();
}



00653 GHOST_TInt32 GHOST_GetWidthRectangle(GHOST_RectangleHandle rectanglehandle)
{
      return ((GHOST_Rect*)rectanglehandle)->getWidth();
}



00660 GHOST_TInt32 GHOST_GetHeightRectangle(GHOST_RectangleHandle rectanglehandle)
{
      return ((GHOST_Rect*)rectanglehandle)->getHeight();
}



00667 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;
}


00682 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);
}



00693 GHOST_TSuccess GHOST_IsEmptyRectangle(GHOST_RectangleHandle rectanglehandle)
{
      GHOST_TSuccess result = GHOST_kFailure;

      if (((GHOST_Rect*)rectanglehandle)->isEmpty())
            result = GHOST_kSuccess;

      return result;
}



00705 GHOST_TSuccess GHOST_IsValidRectangle(GHOST_RectangleHandle rectanglehandle)
{
      GHOST_TSuccess result = GHOST_kFailure;

      if(((GHOST_Rect*)rectanglehandle)->isValid())
            result = GHOST_kSuccess;

      return result;
}



00717 void GHOST_InsetRectangle(GHOST_RectangleHandle rectanglehandle,
                                      GHOST_TInt32 i)
{
      ((GHOST_Rect*)rectanglehandle)->inset(i);
}



00725 void GHOST_UnionRectangle(GHOST_RectangleHandle rectanglehandle,
                                      GHOST_RectangleHandle anotherrectanglehandle)
{
      ((GHOST_Rect*)rectanglehandle)->unionRect(*(GHOST_Rect*)anotherrectanglehandle);
}



00733 void GHOST_UnionPointRectangle(GHOST_RectangleHandle rectanglehandle,
                                             GHOST_TInt32 x,
                                             GHOST_TInt32 y)
{
      ((GHOST_Rect*)rectanglehandle)->unionPoint(x, y);
}



00742 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;
}



00756 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;
}



00768 void GHOST_SetCenterRectangle(GHOST_RectangleHandle rectanglehandle,
                                            GHOST_TInt32 cx,
                                            GHOST_TInt32 cy)
{
      ((GHOST_Rect*)rectanglehandle)->setCenter(cx, cy);
}



00777 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);
}



00788 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;
}




Generated by  Doxygen 1.6.0   Back to index