Skip to content
Snippets Groups Projects
Commit f7b9418d authored by Campbell Barton's avatar Campbell Barton
Browse files

build option to use SDL 1.3 for GHOST rather then X11/Win32/Cocoa api's,

This opens up the option for blender to be more easily ported to other devices, OS's.

TODO
- continuous grab.
- text glitch with multiple windows (was a bug in X11 too for a while, will check on this)
parent b90535cc
Branches
Tags
No related merge requests found
......@@ -109,6 +109,9 @@ option(WITH_PLAYER "Build Player" OFF)
option(WITH_AUDASPACE "Build with blenders audio library" ON)
mark_as_advanced(WITH_AUDASPACE)
option(WITH_SDL_GHOST "Enable building blender against SDL for windowing rather then the native APIs" OFF)
mark_as_advanced(WITH_SDL_GHOST)
option(WITH_HEADLESS "Build without graphical support (renderfarm, server mode only)" OFF)
mark_as_advanced(WITH_HEADLESS)
......@@ -209,6 +212,10 @@ if(NOT WITH_AUDASPACE AND (WITH_OPENAL OR WITH_SDL OR WITH_JACK))
message(FATAL_ERROR "WITH_OPENAL/WITH_SDL/WITH_JACK/WITH_CODEC_FFMPEG require WITH_AUDASPACE")
endif()
if(NOT WITH_SDL AND WITH_SDL_GHOST)
message(FATAL_ERROR "WITH_SDL_GHOST requires WITH_SDL to be ON")
endif()
if(NOT WITH_IMAGE_OPENJPEG AND WITH_IMAGE_REDCODE)
message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG")
endif()
......@@ -433,7 +440,7 @@ if(UNIX AND NOT APPLE)
# OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
if(NOT WITH_HEADLESS)
if((NOT WITH_HEADLESS) AND (NOT WITH_SDL_GHOST))
find_package(X11 REQUIRED)
find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
......
......@@ -89,6 +89,7 @@ set(SRC
intern/GHOST_WindowManager.h
)
if(WITH_HEADLESS OR WITH_SDL_GHOST)
if(WITH_HEADLESS)
list(APPEND SRC
intern/GHOST_DisplayManagerNULL.h
......@@ -96,6 +97,19 @@ if(WITH_HEADLESS)
intern/GHOST_WindowNULL.h
)
add_definitions(-DWITH_HEADLESS)
else()
list(APPEND SRC
intern/GHOST_DisplayManagerSDL.cpp
intern/GHOST_SystemSDL.cpp
intern/GHOST_WindowSDL.cpp
intern/GHOST_DisplayManagerSDL.h
intern/GHOST_SystemSDL.h
intern/GHOST_WindowSDL.h
)
add_definitions(-DWITH_SDL_GHOST)
endif()
# ack, this is still system dependant
if(APPLE)
......@@ -124,6 +138,8 @@ if(WITH_HEADLESS)
)
endif()
list(APPEND INC_SYS ${SDL_INCLUDE_DIR})
elseif(APPLE)
if(WITH_COCOA)
list(APPEND SRC
......
/*
* $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.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManagerSDL.cpp
* \ingroup GHOST
*/
#include "GHOST_SystemSDL.h"
#include "GHOST_DisplayManagerSDL.h"
GHOST_DisplayManagerSDL::GHOST_DisplayManagerSDL(GHOST_SystemSDL *system)
:
GHOST_DisplayManager(),
m_system(system)
{
/* do nothing */
}
GHOST_TSuccess
GHOST_DisplayManagerSDL::getNumDisplays(GHOST_TUns8& numDisplays)
{
numDisplays= SDL_GetNumVideoDisplays();
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_DisplayManagerSDL::getNumDisplaySettings(GHOST_TUns8 display,
GHOST_TInt32& numSettings)
{
GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n");
numSettings= GHOST_TInt32(1);
return GHOST_kSuccess;
}
GHOST_TSuccess
GHOST_DisplayManagerSDL::getDisplaySetting(GHOST_TUns8 display,
GHOST_TInt32 index,
GHOST_DisplaySetting& setting)
{
GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n");
GHOST_ASSERT(index < 1, "Requested setting outside of valid range.\n");
SDL_DisplayMode mode;
SDL_GetDesktopDisplayMode(display, &mode);
setting.xPixels= mode.w;
setting.yPixels= mode.h;
setting.bpp= SDL_BYTESPERPIXEL(mode.format);
/* assume 60 when unset */
setting.frequency= mode.refresh_rate ? mode.refresh_rate : 60;
return GHOST_kSuccess;
}
GHOST_TSuccess
GHOST_DisplayManagerSDL::getCurrentDisplaySetting(GHOST_TUns8 display,
GHOST_DisplaySetting& setting)
{
return getDisplaySetting(display,GHOST_TInt32(0),setting);
}
GHOST_TSuccess
GHOST_DisplayManagerSDL:: 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;
}
/*
* $Id: GHOST_DisplayManagerSDL.h 37194 2011-06-05 00:10:20Z gsrb3d $
* ***** 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): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_DisplayManagerSDL.h
* \ingroup GHOST
* Declaration of GHOST_DisplayManagerSDL class.
*/
#ifndef _GHOST_DISPLAY_MANAGER_SDL_H_
#define _GHOST_DISPLAY_MANAGER_SDL_H_
#include "GHOST_DisplayManager.h"
extern "C" {
#include "SDL.h"
}
class GHOST_SystemSDL;
class GHOST_DisplayManagerSDL : public GHOST_DisplayManager
{
public:
GHOST_DisplayManagerSDL(GHOST_SystemSDL *system);
GHOST_TSuccess
getNumDisplays(GHOST_TUns8& numDisplays);
GHOST_TSuccess
getNumDisplaySettings(GHOST_TUns8 display,
GHOST_TInt32& numSettings);
GHOST_TSuccess
getDisplaySetting(GHOST_TUns8 display,
GHOST_TInt32 index,
GHOST_DisplaySetting& setting);
GHOST_TSuccess
getCurrentDisplaySetting(GHOST_TUns8 display,
GHOST_DisplaySetting& setting);
GHOST_TSuccess
setCurrentDisplaySetting(GHOST_TUns8 display,
const GHOST_DisplaySetting& setting);
private :
GHOST_SystemSDL * m_system;
};
#endif /* _GHOST_DISPLAY_MANAGER_SDL_H_ */
......@@ -43,6 +43,8 @@
#ifdef WITH_HEADLESS
# include "GHOST_SystemNULL.h"
#elif defined(WITH_SDL_GHOST)
# include "GHOST_SystemSDL.h"
#elif defined(WIN32)
# include "GHOST_SystemWin32.h"
#else
......@@ -67,6 +69,8 @@ GHOST_TSuccess GHOST_ISystem::createSystem()
if (!m_system) {
#ifdef WITH_HEADLESS
m_system = new GHOST_SystemNULL();
#elif defined(WITH_SDL_GHOST)
m_system = new GHOST_SystemSDL();
#elif defined(WIN32)
m_system = new GHOST_SystemWin32 ();
#else
......
......@@ -85,6 +85,8 @@ GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
/* do nothing */
#elif defined(_WIN32) || defined(__APPLE__)
m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);
#elif defined(WITH_SDL_GHOST)
/* do nothing */
#else
GHOST_SystemX11 *sys;
sys = static_cast<GHOST_SystemX11*>(GHOST_ISystem::getSystem());
......
/*
* $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.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemSDL.cpp
* \ingroup GHOST
*/
#include <assert.h>
#include "GHOST_SystemSDL.h"
#include "GHOST_WindowManager.h"
#include "GHOST_EventCursor.h"
#include "GHOST_EventKey.h"
#include "GHOST_EventButton.h"
#include "GHOST_EventWheel.h"
GHOST_SystemSDL::GHOST_SystemSDL()
:
GHOST_System()
{
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) {
printf ("Error initializing SDL: %s\n", SDL_GetError());
}
/* SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); */
/* SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
}
GHOST_SystemSDL::~GHOST_SystemSDL()
{
SDL_Quit();
}
GHOST_IWindow *
GHOST_SystemSDL::createWindow(const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
GHOST_TUns32 width,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
bool stereoVisual,
const GHOST_TUns16 numOfAASamples,
const GHOST_TEmbedderWindowID parentWindow
)
{
GHOST_WindowSDL *window= NULL;
window= new GHOST_WindowSDL (this, title, left, top, width, height, state, parentWindow, type, stereoVisual, 1);
if (window) {
if (window->getValid()) {
m_windowManager->addWindow(window);
pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window));
}
else {
delete window;
window= NULL;
}
}
return window;
}
GHOST_TSuccess
GHOST_SystemSDL::init() {
GHOST_TSuccess success = GHOST_System::init();
if (success) {
m_displayManager = new GHOST_DisplayManagerSDL(this);
if (m_displayManager) {
return GHOST_kSuccess;
}
}
return GHOST_kFailure;
}
void
GHOST_SystemSDL::getMainDisplayDimensions(GHOST_TUns32& width,
GHOST_TUns32& height) const
{
SDL_DisplayMode mode;
SDL_GetCurrentDisplayMode(0, &mode); /* note, always 0 display */
width= mode.w;
height= mode.h;
}
GHOST_TUns8
GHOST_SystemSDL::getNumDisplays() const
{
return SDL_GetNumVideoDisplays();
}
GHOST_TSuccess
GHOST_SystemSDL::getModifierKeys(GHOST_ModifierKeys& keys) const
{
SDL_Keymod mod= SDL_GetModState();
keys.set(GHOST_kModifierKeyLeftShift, (mod & KMOD_LSHIFT) != 0);
keys.set(GHOST_kModifierKeyRightShift, (mod & KMOD_RSHIFT) != 0);
keys.set(GHOST_kModifierKeyLeftControl, (mod & KMOD_LCTRL) != 0);
keys.set(GHOST_kModifierKeyRightControl, (mod & KMOD_RCTRL) != 0);
keys.set(GHOST_kModifierKeyLeftAlt, (mod & KMOD_LALT) != 0);
keys.set(GHOST_kModifierKeyRightAlt, (mod & KMOD_RALT) != 0);
keys.set(GHOST_kModifierKeyOS, (mod & (KMOD_LGUI|KMOD_RGUI)) != 0);
return GHOST_kSuccess;
}
#define GXMAP(k,x,y) case x: k= y; break;
static GHOST_TKey
convertSDLKey(SDL_Scancode key)
{
GHOST_TKey type;
if ((key >= SDL_SCANCODE_A) && (key <= SDL_SCANCODE_Z)) {
type= GHOST_TKey( key - SDL_SCANCODE_A + int(GHOST_kKeyA));
} else if ((key >= SDL_SCANCODE_1) && (key <= SDL_SCANCODE_0)) {
type= GHOST_TKey(key - SDL_SCANCODE_1 + int(GHOST_kKey0));
} else if ((key >= SDL_SCANCODE_F1) && (key <= SDL_SCANCODE_F12)) {
type= GHOST_TKey(key - SDL_SCANCODE_F1 + int(GHOST_kKeyF1));
} else if ((key >= SDL_SCANCODE_F13) && (key <= SDL_SCANCODE_F24)) {
type= GHOST_TKey(key - SDL_SCANCODE_F13 + int(GHOST_kKeyF13));
} else {
switch(key) {
/* TODO SDL_SCANCODE_NONUSBACKSLASH */
GXMAP(type,SDL_SCANCODE_BACKSPACE, GHOST_kKeyBackSpace);
GXMAP(type,SDL_SCANCODE_TAB, GHOST_kKeyTab);
GXMAP(type,SDL_SCANCODE_RETURN, GHOST_kKeyEnter);
GXMAP(type,SDL_SCANCODE_ESCAPE, GHOST_kKeyEsc);
GXMAP(type,SDL_SCANCODE_SPACE, GHOST_kKeySpace);
GXMAP(type,SDL_SCANCODE_SEMICOLON, GHOST_kKeySemicolon);
GXMAP(type,SDL_SCANCODE_PERIOD, GHOST_kKeyPeriod);
GXMAP(type,SDL_SCANCODE_COMMA, GHOST_kKeyComma);
GXMAP(type,SDL_SCANCODE_APOSTROPHE, GHOST_kKeyQuote);
GXMAP(type,SDL_SCANCODE_GRAVE, GHOST_kKeyAccentGrave);
GXMAP(type,SDL_SCANCODE_MINUS, GHOST_kKeyMinus);
GXMAP(type,SDL_SCANCODE_SLASH, GHOST_kKeySlash);
GXMAP(type,SDL_SCANCODE_BACKSLASH, GHOST_kKeyBackslash);
GXMAP(type,SDL_SCANCODE_KP_EQUALS, GHOST_kKeyEqual);
GXMAP(type,SDL_SCANCODE_LEFTBRACKET, GHOST_kKeyLeftBracket);
GXMAP(type,SDL_SCANCODE_RIGHTBRACKET, GHOST_kKeyRightBracket);
GXMAP(type,SDL_SCANCODE_PAUSE, GHOST_kKeyPause);
GXMAP(type,SDL_SCANCODE_LSHIFT, GHOST_kKeyLeftShift);
GXMAP(type,SDL_SCANCODE_RSHIFT, GHOST_kKeyRightShift);
GXMAP(type,SDL_SCANCODE_LCTRL, GHOST_kKeyLeftControl);
GXMAP(type,SDL_SCANCODE_RCTRL, GHOST_kKeyRightControl);
GXMAP(type,SDL_SCANCODE_LALT, GHOST_kKeyLeftAlt);
GXMAP(type,SDL_SCANCODE_RALT, GHOST_kKeyRightAlt);
GXMAP(type,SDL_SCANCODE_RGUI, GHOST_kKeyOS);
GXMAP(type,SDL_SCANCODE_INSERT, GHOST_kKeyInsert);
GXMAP(type,SDL_SCANCODE_DELETE, GHOST_kKeyDelete);
GXMAP(type,SDL_SCANCODE_HOME, GHOST_kKeyHome);
GXMAP(type,SDL_SCANCODE_END, GHOST_kKeyEnd);
GXMAP(type,SDL_SCANCODE_PAGEUP, GHOST_kKeyUpPage);
GXMAP(type,SDL_SCANCODE_PAGEDOWN, GHOST_kKeyDownPage);
GXMAP(type,SDL_SCANCODE_LEFT, GHOST_kKeyLeftArrow);
GXMAP(type,SDL_SCANCODE_RIGHT, GHOST_kKeyRightArrow);
GXMAP(type,SDL_SCANCODE_UP, GHOST_kKeyUpArrow);
GXMAP(type,SDL_SCANCODE_DOWN, GHOST_kKeyDownArrow);
GXMAP(type,SDL_SCANCODE_CAPSLOCK, GHOST_kKeyCapsLock);
GXMAP(type,SDL_SCANCODE_SCROLLLOCK, GHOST_kKeyScrollLock);
GXMAP(type,SDL_SCANCODE_NUMLOCKCLEAR, GHOST_kKeyNumLock);
/* keypad events */
/* note, sdl defines a bunch of kp defines I never saw before like
* SDL_SCANCODE_KP_PERCENT, SDL_SCANCODE_KP_XOR - campbell */
GXMAP(type,SDL_SCANCODE_KP_0, GHOST_kKeyNumpad0);
GXMAP(type,SDL_SCANCODE_KP_1, GHOST_kKeyNumpad1);
GXMAP(type,SDL_SCANCODE_KP_2, GHOST_kKeyNumpad2);
GXMAP(type,SDL_SCANCODE_KP_3, GHOST_kKeyNumpad3);
GXMAP(type,SDL_SCANCODE_KP_4, GHOST_kKeyNumpad4);
GXMAP(type,SDL_SCANCODE_KP_5, GHOST_kKeyNumpad5);
GXMAP(type,SDL_SCANCODE_KP_6, GHOST_kKeyNumpad6);
GXMAP(type,SDL_SCANCODE_KP_7, GHOST_kKeyNumpad7);
GXMAP(type,SDL_SCANCODE_KP_8, GHOST_kKeyNumpad8);
GXMAP(type,SDL_SCANCODE_KP_9, GHOST_kKeyNumpad9);
GXMAP(type,SDL_SCANCODE_KP_PERIOD, GHOST_kKeyNumpadPeriod);
GXMAP(type,SDL_SCANCODE_KP_ENTER, GHOST_kKeyNumpadEnter);
GXMAP(type,SDL_SCANCODE_KP_PLUS, GHOST_kKeyNumpadPlus);
GXMAP(type,SDL_SCANCODE_KP_MINUS, GHOST_kKeyNumpadMinus);
GXMAP(type,SDL_SCANCODE_KP_MULTIPLY, GHOST_kKeyNumpadAsterisk);
GXMAP(type,SDL_SCANCODE_KP_DIVIDE, GHOST_kKeyNumpadSlash);
/* Media keys in some keyboards and laptops with XFree86/Xorg */
GXMAP(type,SDL_SCANCODE_AUDIOPLAY, GHOST_kKeyMediaPlay);
GXMAP(type,SDL_SCANCODE_AUDIOSTOP, GHOST_kKeyMediaStop);
GXMAP(type,SDL_SCANCODE_AUDIOPREV, GHOST_kKeyMediaFirst);
// GXMAP(type,XF86XK_AudioRewind, GHOST_kKeyMediaFirst);
GXMAP(type,SDL_SCANCODE_AUDIONEXT, GHOST_kKeyMediaLast);
default:
type= GHOST_kKeyUnknown;
break;
}
}
return type;
}
#undef GXMAP
void
GHOST_SystemSDL::processEvent(SDL_Event *sdl_event)
{
GHOST_Event * g_event= NULL;
switch(sdl_event->type) {
case SDL_WINDOWEVENT:
{
SDL_WindowEvent &sdl_sub_evt= sdl_event->window;
GHOST_WindowSDL *window= findGhostWindow(SDL_GetWindowFromID(sdl_sub_evt.windowID));
//assert(window != NULL); // can be NULL on close window.
switch (sdl_sub_evt.event) {
case SDL_WINDOWEVENT_EXPOSED:
g_event= new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowUpdate, window);
break;
case SDL_WINDOWEVENT_RESIZED:
g_event= new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window);
break;
case SDL_WINDOWEVENT_MOVED:
g_event= new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowMove, window);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
g_event= new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window);
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
g_event= new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowDeactivate, window);
break;
case SDL_WINDOWEVENT_CLOSE:
g_event= new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowClose, window);
break;
}
}
break;
case SDL_QUIT:
g_event= new GHOST_Event(getMilliSeconds(), GHOST_kEventQuit, NULL);
break;
case SDL_MOUSEMOTION:
{
SDL_MouseMotionEvent &sdl_sub_evt= sdl_event->motion;
GHOST_WindowSDL *window= findGhostWindow(SDL_GetWindowFromID(sdl_sub_evt.windowID));
assert(window != NULL);
g_event= new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, sdl_sub_evt.x, sdl_sub_evt.y);
break;
}
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
{
SDL_MouseButtonEvent &sdl_sub_evt= sdl_event->button;
GHOST_TButtonMask gbmask= GHOST_kButtonMaskLeft;
GHOST_TEventType type= (sdl_sub_evt.state==SDL_PRESSED) ? GHOST_kEventButtonDown : GHOST_kEventButtonUp;
GHOST_WindowSDL *window= findGhostWindow(SDL_GetWindowFromID(sdl_sub_evt.windowID));
assert(window != NULL);
/* process rest of normal mouse buttons */
if(sdl_sub_evt.button == SDL_BUTTON_LEFT)
gbmask= GHOST_kButtonMaskLeft;
else if(sdl_sub_evt.button == SDL_BUTTON_MIDDLE)
gbmask= GHOST_kButtonMaskMiddle;
else if(sdl_sub_evt.button == SDL_BUTTON_RIGHT)
gbmask= GHOST_kButtonMaskRight;
/* these buttons are untested! */
else if(sdl_sub_evt.button == SDL_BUTTON_X1)
gbmask= GHOST_kButtonMaskButton4;
else if(sdl_sub_evt.button == SDL_BUTTON_X2)
gbmask= GHOST_kButtonMaskButton5;
else
break;
g_event= new GHOST_EventButton(getMilliSeconds(), type, window, gbmask);
break;
}
case SDL_MOUSEWHEEL:
{
SDL_MouseWheelEvent &sdl_sub_evt= sdl_event->wheel;
GHOST_WindowSDL *window= findGhostWindow(SDL_GetWindowFromID(sdl_sub_evt.windowID));
assert(window != NULL);
g_event= new GHOST_EventWheel(getMilliSeconds(), window, sdl_sub_evt.y);
}
break;
case SDL_KEYDOWN:
case SDL_KEYUP:
{
SDL_KeyboardEvent &sdl_sub_evt= sdl_event->key;
GHOST_TEventType type= (sdl_sub_evt.state == SDL_PRESSED) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp;
GHOST_WindowSDL *window= findGhostWindow(SDL_GetWindowFromID(sdl_sub_evt.windowID));
assert(window != NULL);
GHOST_TKey gkey= convertSDLKey(sdl_sub_evt.keysym.scancode);
/* note, the sdl_sub_evt.keysym.sym is truncated, for unicode support ghost has to be modified */
g_event= new GHOST_EventKey(getMilliSeconds(), type, window, gkey, sdl_sub_evt.keysym.sym);
}
break;
}
if (g_event) {
pushEvent(g_event);
}
}
GHOST_TSuccess
GHOST_SystemSDL::getCursorPosition(GHOST_TInt32& x,
GHOST_TInt32& y) const
{
int xi, yi;
SDL_GetMouseState(&xi, &yi);
x= xi;
y= yi;
return GHOST_kSuccess;
}
GHOST_TSuccess
GHOST_SystemSDL::setCursorPosition(GHOST_TInt32 x,
GHOST_TInt32 y)
{
// SDL_SendMouseMotion(SDL, SDL_FALSE, x, y); // NOT EXPOSED
SDL_WarpMouseInWindow(NULL, x, y);
return GHOST_kSuccess;
}
bool
GHOST_SystemSDL::generateWindowExposeEvents()
{
vector<GHOST_WindowSDL *>::iterator w_start= m_dirty_windows.begin();
vector<GHOST_WindowSDL *>::const_iterator w_end= m_dirty_windows.end();
bool anyProcessed= false;
for (;w_start != w_end; ++w_start) {
GHOST_Event * g_event= new
GHOST_Event(
getMilliSeconds(),
GHOST_kEventWindowUpdate,
*w_start
);
(*w_start)->validate();
if (g_event) {
printf("Expose events pushed\n");
pushEvent(g_event);
anyProcessed= true;
}
}
m_dirty_windows.clear();
return anyProcessed;
}
bool
GHOST_SystemSDL::processEvents(bool waitForEvent)
{
// Get all the current events -- translate them into
// ghost events and call base class pushEvent() method.
bool anyProcessed= false;
do {
GHOST_TimerManager* timerMgr= getTimerManager();
if (waitForEvent && m_dirty_windows.empty() && !SDL_HasEvents(SDL_FIRSTEVENT, SDL_LASTEVENT)) {
GHOST_TUns64 next= timerMgr->nextFireTime();
if (next==GHOST_kFireTimeNever) {
SDL_WaitEventTimeout(NULL, -1);
//SleepTillEvent(m_display, -1);
} else {
GHOST_TInt64 maxSleep= next - getMilliSeconds();
if(maxSleep >= 0) {
SDL_WaitEventTimeout(NULL, next - getMilliSeconds());
// SleepTillEvent(m_display, next - getMilliSeconds()); // X11
}
}
}
if (timerMgr->fireTimers(getMilliSeconds())) {
anyProcessed= true;
}
SDL_Event sdl_event;
while (SDL_PollEvent(&sdl_event)) {
processEvent(&sdl_event);
anyProcessed= true;
}
if (generateWindowExposeEvents()) {
anyProcessed= true;
}
} while (waitForEvent && !anyProcessed);
return anyProcessed;
}
GHOST_WindowSDL *
GHOST_SystemSDL::findGhostWindow(SDL_Window *sdl_win)
{
if (sdl_win == NULL) return NULL;
// It is not entirely safe to do this as the backptr may point
// to a window that has recently been removed.
// We should always check the window manager's list of windows
// and only process events on these windows.
vector<GHOST_IWindow *> & win_vec= m_windowManager->getWindows();
vector<GHOST_IWindow *>::iterator win_it= win_vec.begin();
vector<GHOST_IWindow *>::const_iterator win_end= win_vec.end();
for (; win_it != win_end; ++win_it) {
GHOST_WindowSDL * window= static_cast<GHOST_WindowSDL *>(*win_it);
if (window->getSDLWindow() == sdl_win) {
return window;
}
}
return NULL;
}
void
GHOST_SystemSDL::addDirtyWindow(GHOST_WindowSDL *bad_wind)
{
GHOST_ASSERT((bad_wind != NULL), "addDirtyWindow() NULL ptr trapped (window)");
m_dirty_windows.push_back(bad_wind);
}
GHOST_TSuccess GHOST_SystemSDL::getButtons(GHOST_Buttons& buttons) const
{
Uint8 state= SDL_GetMouseState(NULL, NULL);
buttons.set(GHOST_kButtonMaskLeft, (state & SDL_BUTTON_LMASK) != 0);
buttons.set(GHOST_kButtonMaskMiddle, (state & SDL_BUTTON_MMASK) != 0);
buttons.set(GHOST_kButtonMaskRight, (state & SDL_BUTTON_RMASK) != 0);
return GHOST_kSuccess;
}
GHOST_TUns8 *
GHOST_SystemSDL::getClipboard(bool selection) const
{
return (GHOST_TUns8 *)SDL_GetClipboardText();
}
void
GHOST_SystemSDL::putClipboard(GHOST_TInt8 *buffer, bool selection) const
{
SDL_SetClipboardText(buffer);
}
GHOST_TUns64
GHOST_SystemSDL::getMilliSeconds()
{
return GHOST_TUns64(SDL_GetTicks()); /* note, 32 -> 64bits */
}
/*
* $Id: GHOST_SystemSDL.h 37194 2011-06-05 00:10:20Z gsrb3d $
* ***** 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): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_SystemSDL.h
* \ingroup GHOST
* Declaration of GHOST_SystemSDL class.
*/
#ifndef _GHOST_SYSTEM_SDL_H_
#define _GHOST_SYSTEM_SDL_H_
#include "GHOST_System.h"
#include "../GHOST_Types.h"
#include "GHOST_DisplayManagerSDL.h"
#include "GHOST_TimerManager.h"
#include "GHOST_WindowSDL.h"
#include "GHOST_Event.h"
extern "C" {
#include "SDL.h"
}
class GHOST_WindowSDL;
class GHOST_SystemSDL : public GHOST_System {
public:
void addDirtyWindow(GHOST_WindowSDL *bad_wind);
GHOST_SystemSDL();
~GHOST_SystemSDL();
bool
processEvents(bool waitForEvent);
int
toggleConsole(int action) { return 0; }
GHOST_TSuccess
getModifierKeys(GHOST_ModifierKeys& keys) const;
GHOST_TSuccess
getButtons(GHOST_Buttons& buttons) const;
GHOST_TUns8 *
getClipboard(bool selection) const;
void
putClipboard(GHOST_TInt8 *buffer, bool selection) const;
GHOST_TUns64
getMilliSeconds();
GHOST_TUns8
getNumDisplays() const;
GHOST_TSuccess
getCursorPosition(GHOST_TInt32& x,
GHOST_TInt32& y) const;
GHOST_TSuccess
setCursorPosition(GHOST_TInt32 x,
GHOST_TInt32 y);
void
getMainDisplayDimensions(GHOST_TUns32& width,
GHOST_TUns32& height) const;
private:
GHOST_TSuccess
init();
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,
bool stereoVisual,
const GHOST_TUns16 numOfAASamples,
const GHOST_TEmbedderWindowID parentWindow
);
/* SDL spesific */
GHOST_WindowSDL * findGhostWindow(SDL_Window *sdl_win);
bool
generateWindowExposeEvents();
void
processEvent(SDL_Event *sdl_event);
/// The vector of windows that need to be updated.
std::vector<GHOST_WindowSDL *> m_dirty_windows;
};
#endif
This diff is collapsed.
/*
* $Id: GHOST_WindowSDL.h 38022 2011-07-01 15:15:22Z campbellbarton $
* ***** 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): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file ghost/intern/GHOST_WindowSDL.h
* \ingroup GHOST
* Declaration of GHOST_WindowSDL class.
*/
#ifndef _GHOST_WINDOWSDL_H_
#define _GHOST_WINDOWSDL_H_
#include "GHOST_Window.h"
#include "GHOST_SystemSDL.h"
#include <map>
extern "C" {
#include "SDL.h"
}
class STR_String;
class GHOST_WindowSDL : public GHOST_Window
{
private :
GHOST_SystemSDL * m_system;
bool m_invalid_window;
SDL_Window * m_sdl_win;
SDL_GLContext m_sdl_glcontext;
SDL_Cursor * m_sdl_custom_cursor;
public:
const GHOST_TabletData* GetTabletData() { return NULL; }
GHOST_WindowSDL(GHOST_SystemSDL *system,
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,
const bool stereoVisual,
const GHOST_TUns16 numOfAASamples
);
~GHOST_WindowSDL();
/* SDL spesific */
SDL_Window *
getSDLWindow(
){
return m_sdl_win;
}
GHOST_TSuccess invalidate(void);
/**
* called by the X11 system implementation when expose events
* for the window have been pushed onto the GHOST queue
*/
void validate()
{
m_invalid_window = false;
}
bool getValid( ) const
{
return (m_sdl_win != NULL);
}
protected:
GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
GHOST_TSuccess removeDrawingContext();
GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color);
GHOST_TSuccess setWindowCursorVisibility(bool visible);
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);
/* TODO */
void screenToClient( GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY ) const { outX = inX; outY = inY; }
void clientToScreen( GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY ) const { outX = inX; outY = inY; }
GHOST_TSuccess swapBuffers();
GHOST_TSuccess activateDrawingContext();
GHOST_TSuccess setState(GHOST_TWindowState state);
GHOST_TWindowState getState() const;
GHOST_TSuccess setOrder(GHOST_TWindowOrder order) { return GHOST_kSuccess; } // TODO
};
#endif // _GHOST_WINDOWSDL_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment