Files
test/intern/ghost/intern/GHOST_System.cpp

412 lines
11 KiB
C++
Raw Normal View History

2011-02-25 11:28:33 +00:00
/*
2002-10-12 11:37:38 +00:00
* 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.
2002-10-12 11:37:38 +00:00
*
* 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,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2002-10-12 11:37:38 +00:00
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*/
/** \file
* \ingroup GHOST
2002-10-12 11:37:38 +00:00
*/
#include "GHOST_System.h"
#include <time.h>
#include <stdio.h> /* just for printf */
2002-10-12 11:37:38 +00:00
#include "GHOST_DisplayManager.h"
#include "GHOST_EventManager.h"
#include "GHOST_TimerTask.h"
#include "GHOST_TimerManager.h"
#include "GHOST_WindowManager.h"
#ifdef WITH_INPUT_NDOF
# include "GHOST_NDOFManager.h"
#endif
2002-10-12 11:37:38 +00:00
GHOST_System::GHOST_System()
2014-07-24 21:39:27 +10:00
: m_nativePixel(false),
m_windowFocus(true),
2014-07-24 21:39:27 +10:00
m_displayManager(NULL),
m_timerManager(NULL),
m_windowManager(NULL),
m_eventManager(NULL),
#ifdef WITH_INPUT_NDOF
m_ndofManager(0),
#endif
m_tabletAPI(GHOST_kTabletAutomatic),
m_is_debug_enabled(false)
2002-10-12 11:37:38 +00:00
{
}
GHOST_System::~GHOST_System()
{
exit();
2002-10-12 11:37:38 +00:00
}
GHOST_TUns64 GHOST_System::getMilliSeconds() const
{
GHOST_TUns64 millis = ::clock();
if (CLOCKS_PER_SEC != 1000) {
millis *= 1000;
millis /= CLOCKS_PER_SEC;
}
return millis;
2002-10-12 11:37:38 +00:00
}
2012-05-19 09:57:55 +00:00
GHOST_ITimerTask *GHOST_System::installTimer(GHOST_TUns64 delay,
2011-12-24 02:32:08 +00:00
GHOST_TUns64 interval,
GHOST_TimerProcPtr timerProc,
GHOST_TUserDataPtr userData)
2002-10-12 11:37:38 +00:00
{
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 = NULL;
}
}
return timer;
2002-10-12 11:37:38 +00:00
}
2012-05-19 09:57:55 +00:00
GHOST_TSuccess GHOST_System::removeTimer(GHOST_ITimerTask *timerTask)
2002-10-12 11:37:38 +00:00
{
GHOST_TSuccess success = GHOST_kFailure;
if (timerTask) {
success = m_timerManager->removeTimer((GHOST_TimerTask *)timerTask);
}
return success;
2002-10-12 11:37:38 +00:00
}
2012-05-19 09:57:55 +00:00
GHOST_TSuccess GHOST_System::disposeWindow(GHOST_IWindow *window)
2002-10-12 11:37:38 +00:00
{
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;
2002-10-12 11:37:38 +00:00
}
GHOST_IContext *GHOST_System::createOffscreenContext(GHOST_TDrawingContextType type)
{
switch (type) {
case GHOST_kDrawingContextTypeOpenGL:
return createOffscreenContext();
default:
return NULL;
}
}
2012-05-19 09:57:55 +00:00
bool GHOST_System::validWindow(GHOST_IWindow *window)
2002-10-12 11:37:38 +00:00
{
return m_windowManager->getWindowFound(window);
2002-10-12 11:37:38 +00:00
}
GHOST_TSuccess GHOST_System::beginFullScreen(const GHOST_DisplaySetting &setting,
GHOST_IWindow **window,
const bool stereoVisual,
const bool alphaBackground)
2002-10-12 11:37:38 +00:00
{
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, setting, stereoVisual, alphaBackground);
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;
2002-10-12 11:37:38 +00:00
}
GHOST_TSuccess GHOST_System::updateFullScreen(const GHOST_DisplaySetting &setting,
GHOST_IWindow ** /*window*/)
{
GHOST_TSuccess success = GHOST_kFailure;
GHOST_ASSERT(m_windowManager, "GHOST_System::updateFullScreen(): invalid window manager");
if (m_displayManager) {
if (m_windowManager->getFullScreen()) {
success = m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay,
setting);
}
}
return success;
}
2002-10-12 11:37:38 +00:00
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;
2002-10-12 11:37:38 +00:00
}
bool GHOST_System::getFullScreen(void)
{
bool fullScreen;
if (m_windowManager) {
fullScreen = m_windowManager->getFullScreen();
}
else {
fullScreen = false;
}
return fullScreen;
2002-10-12 11:37:38 +00:00
}
void GHOST_System::dispatchEvents()
2002-10-12 11:37:38 +00:00
{
#ifdef WITH_INPUT_NDOF
// NDOF Motion event is sent only once per dispatch, so do it now:
if (m_ndofManager) {
m_ndofManager->sendMotionEvent();
}
#endif
if (m_eventManager) {
m_eventManager->dispatchEvents();
}
2002-10-12 11:37:38 +00:00
m_timerManager->fireTimers(getMilliSeconds());
2002-10-12 11:37:38 +00:00
}
2012-05-19 09:57:55 +00:00
GHOST_TSuccess GHOST_System::addEventConsumer(GHOST_IEventConsumer *consumer)
2002-10-12 11:37:38 +00:00
{
GHOST_TSuccess success;
if (m_eventManager) {
success = m_eventManager->addConsumer(consumer);
}
else {
success = GHOST_kFailure;
}
return success;
2002-10-12 11:37:38 +00:00
}
2012-05-19 09:57:55 +00:00
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;
}
2002-10-12 11:37:38 +00:00
2012-05-19 09:57:55 +00:00
GHOST_TSuccess GHOST_System::pushEvent(GHOST_IEvent *event)
2002-10-12 11:37:38 +00:00
{
GHOST_TSuccess success;
if (m_eventManager) {
success = m_eventManager->pushEvent(event);
}
else {
success = GHOST_kFailure;
}
return success;
2002-10-12 11:37:38 +00:00
}
GHOST_TSuccess GHOST_System::getModifierKeyState(GHOST_TModifierKeyMask mask, bool &isDown) const
2002-10-12 11:37:38 +00:00
{
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;
2002-10-12 11:37:38 +00:00
}
GHOST_TSuccess GHOST_System::getButtonState(GHOST_TButtonMask mask, bool &isDown) const
2002-10-12 11:37:38 +00:00
{
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;
2002-10-12 11:37:38 +00:00
}
void GHOST_System::setTabletAPI(GHOST_TTabletAPI api)
{
m_tabletAPI = api;
}
GHOST_TTabletAPI GHOST_System::getTabletAPI(void)
{
return m_tabletAPI;
}
#ifdef WITH_INPUT_NDOF
void GHOST_System::setNDOFDeadZone(float deadzone)
{
if (this->m_ndofManager) {
this->m_ndofManager->setDeadZone(deadzone);
}
}
#endif
2002-10-12 11:37:38 +00:00
GHOST_TSuccess GHOST_System::init()
{
m_timerManager = new GHOST_TimerManager();
m_windowManager = new GHOST_WindowManager();
m_eventManager = new GHOST_EventManager();
2018-06-04 18:47:57 +02:00
2002-10-12 11:37:38 +00:00
#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;
}
2002-10-12 11:37:38 +00:00
}
GHOST_TSuccess GHOST_System::exit()
{
if (getFullScreen()) {
endFullScreen();
}
delete m_displayManager;
m_displayManager = NULL;
delete m_windowManager;
m_windowManager = NULL;
delete m_timerManager;
m_timerManager = NULL;
delete m_eventManager;
m_eventManager = NULL;
#ifdef WITH_INPUT_NDOF
delete m_ndofManager;
m_ndofManager = NULL;
#endif
return GHOST_kSuccess;
2002-10-12 11:37:38 +00:00
}
GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window **window,
const GHOST_DisplaySetting &settings,
const bool stereoVisual,
const bool alphaBackground)
2002-10-12 11:37:38 +00:00
{
GHOST_GLSettings glSettings = {0};
if (stereoVisual)
glSettings.flags |= GHOST_glStereoVisual;
if (alphaBackground)
glSettings.flags |= GHOST_glAlphaBackground;
/* note: don't use getCurrentDisplaySetting() because on X11 we may
* be zoomed in and the desktop may be bigger then the viewport. */
GHOST_ASSERT(m_displayManager,
"GHOST_System::createFullScreenWindow(): invalid display manager");
// GHOST_PRINT("GHOST_System::createFullScreenWindow(): creating full-screen window\n");
*window = (GHOST_Window *)createWindow(STR_String(""),
0,
0,
settings.xPixels,
settings.yPixels,
GHOST_kWindowStateNormal,
GHOST_kDrawingContextTypeOpenGL,
glSettings,
true /* exclusive */);
return (*window == NULL) ? GHOST_kFailure : GHOST_kSuccess;
2002-10-12 11:37:38 +00:00
}
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
bool GHOST_System::useNativePixel(void)
{
m_nativePixel = true;
return 1;
Holiday coding log :) Nice formatted version (pictures soon): http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability Short list of main changes: - Transparent region option (over main region), added code to blend in/out such panels. - Min size window now 640 x 480 - Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake. - Macbook retina support, use command line --no-native-pixels to disable it - Timeline Marker label was drawing wrong - Trackpad and magic mouse: supports zoom (hold ctrl) - Fix for splash position: removed ghost function and made window size update after creation immediate - Fast undo buffer save now adds UI as well. Could be checked for regular file save even... Quit.blend and temp file saving use this now. - Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)" - New Userpref option "Keep Session" - this always saves quit.blend, and loads on start. This allows keeping UI and data without actual saves, until you actually save. When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header) - Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. - User preferences (themes, keymaps, user settings) now can be saved as a separate file. Old option is called "Save Startup File" the new one "Save User Settings". To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still. - OSX: fixed bug that stopped giving mouse events outside window. This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
}
void GHOST_System::useWindowFocus(const bool use_focus)
{
m_windowFocus = use_focus;
}
void GHOST_System::initDebug(bool is_debug_enabled)
{
m_is_debug_enabled = is_debug_enabled;
}
bool GHOST_System::isDebugEnabled()
{
return m_is_debug_enabled;
}