OSStatus GHOST_SystemCarbon::handleWindowEvent(EventRef event) { WindowRef windowRef; GHOST_WindowCarbon *window; OSStatus err = eventNotHandledErr; // Check if the event was send to a GHOST window ::GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &windowRef); window = (GHOST_WindowCarbon *) ::GetWRefCon(windowRef); if (!validWindow(window)) { return err; } //if (!getFullScreen()) { err = noErr; switch (::GetEventKind(event)) { case kEventWindowClose: pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowClose, window) ); break; case kEventWindowActivated: m_windowManager->setActiveWindow(window); window->loadCursor(window->getCursorVisibility(), window->getCursorShape()); pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window) ); break; case kEventWindowDeactivated: m_windowManager->setWindowInactive(window); pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowDeactivate, window) ); break; case kEventWindowUpdate: //if (getFullScreen()) GHOST_PRINT("GHOST_SystemCarbon::handleWindowEvent(): full-screen update event\n"); pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowUpdate, window) ); break; case kEventWindowBoundsChanged: if (!m_ignoreWindowSizedMessages) { window->updateDrawingContext(); pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window) ); } break; default: err = eventNotHandledErr; break; } // } //else { //window = (GHOST_WindowCarbon*) m_windowManager->getFullScreenWindow(); //GHOST_PRINT("GHOST_SystemCarbon::handleWindowEvent(): full-screen window event, " << window << "\n"); //::RemoveEventFromQueue(::GetMainEventQueue(), event); //} return err; }
GHOST_IWindow *GHOST_SystemCarbon::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_IWindow *window = 0; window = new GHOST_WindowCarbon(title, left, top, width, height, state, type); if (window) { if (window->getValid()) { // Store the pointer to the window GHOST_ASSERT(m_windowManager, "m_windowManager not initialized"); m_windowManager->addWindow(window); m_windowManager->setActiveWindow(window); pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window)); } else { GHOST_PRINT("GHOST_SystemCarbon::createWindow(): window invalid\n"); delete window; window = 0; } } else { GHOST_PRINT("GHOST_SystemCarbon::createWindow(): could not create window\n"); } return window; }
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; }
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; }
VOID Display::init() { struct sigaction action_quit; initscr(); noecho(); m_dispIntvl = Config::getInstance()->getDisplayRefreshTimer(); m_pStats = Stats::getInstance(); getTimeStr(m_timeStr); m_startTime = getMilliSeconds() / 1000; m_remPort = Config::getInstance()->getRemoteGtpcPort(); STRCPY(m_remIpAddrStr, (Config::getInstance()->\ getRemIpAddrStr()).c_str()); m_pMsgVec = &(Scenario::getInstance()->m_msgVec); m_msgVecLen = m_pMsgVec->size(); /* Map exit handlers to curses reset procedure */ memset(&action_quit, 0, sizeof(action_quit)); (*(void **)(&(action_quit.sa_handler))) = (VOID *)screen_exit; sigaction(SIGTERM, &action_quit, NULL); sigaction(SIGINT, &action_quit, NULL); sigaction(SIGKILL, &action_quit, NULL); CLEAR_SCREEN(); }
std::string CCopasiTimeVariable::isoFormat() const { std::stringstream Iso; bool first = true; if (mTime < LLONG_CONST(0)) { CCopasiTimeVariable Tmp(-mTime); Iso << "-"; Iso << Tmp.isoFormat(); return Iso.str(); } if (mTime >= LLONG_CONST(86400000000)) { Iso << LL2String(getDays()) << ":"; first = false; } if (mTime >= LLONG_CONST(3600000000)) Iso << LL2String(getHours(true), first ? 0 : 2) << ":"; if (mTime >= LLONG_CONST(60000000)) Iso << LL2String(getMinutes(true), first ? 0 : 2) << ":"; if (mTime >= LLONG_CONST(1000000)) Iso << LL2String(getSeconds(true), first ? 0 : 2) << "."; else Iso << "0."; Iso << LL2String(getMilliSeconds(true), 3) << LL2String(getMicroSeconds(true), 3); return Iso.str(); }
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; }
/** * @brief -- thread function for running GCS link */ void *runGcsLink(void*){ // Start loop timer unsigned long last_time_gcs_link = getMilliSeconds(); for(;;){ if (comModule.isGcsOpen()) { comModule.updateGcs(); } usleep(10000); // Halt for 10 ms if no bytes incoming } }
BOOL Display::run() { LOG_ENTERFN(); m_lastRunTime = getMilliSeconds(); disp(); pauseTask(); LOG_EXITFN(TRUE); }
bool GHOST_SystemWin32::processEvents(bool waitForEvent) { MSG msg; bool anyProcessed = false; do { GHOST_TimerManager *timerMgr = getTimerManager(); if (waitForEvent && !::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) { #if 1 ::Sleep(1); #else GHOST_TUns64 next = timerMgr->nextFireTime(); GHOST_TInt64 maxSleep = next - getMilliSeconds(); if (next == GHOST_kFireTimeNever) { ::WaitMessage(); } else if (maxSleep >= 0.0) { ::SetTimer(NULL, 0, maxSleep, NULL); ::WaitMessage(); ::KillTimer(NULL, 0); } #endif } if (timerMgr->fireTimers(getMilliSeconds())) { anyProcessed = true; } // Process all the events waiting for us while (::PeekMessageW(&msg, 0, 0, 0, PM_REMOVE) != 0) { // TranslateMessage doesn't alter the message, and doesn't change our raw keyboard data. // Needed for MapVirtualKey or if we ever need to get chars from wm_ime_char or similar. ::TranslateMessage(&msg); ::DispatchMessageW(&msg); anyProcessed = true; } } while (waitForEvent && !anyProcessed); return anyProcessed; }
bool GHOST_SystemWin32::processEvents(bool waitForEvent) { MSG msg; bool anyProcessed = false; do { GHOST_TimerManager* timerMgr = getTimerManager(); if (waitForEvent && !::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) { #if 1 ::Sleep(1); #else GHOST_TUns64 next = timerMgr->nextFireTime(); GHOST_TInt64 maxSleep = next - getMilliSeconds(); if (next == GHOST_kFireTimeNever) { ::WaitMessage(); } else if(maxSleep >= 0.0) { ::SetTimer(NULL, 0, maxSleep, NULL); ::WaitMessage(); ::KillTimer(NULL, 0); } #endif } if (timerMgr->fireTimers(getMilliSeconds())) { anyProcessed = true; } // Process all the events waiting for us while (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE) != 0) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); anyProcessed = true; } } while (waitForEvent && !anyProcessed); return anyProcessed; }
bool GHOST_System::dispatchEvents() { bool handled; if (m_eventManager) { handled = m_eventManager->dispatchEvents(); } else { handled = false; } m_timerManager->fireTimers(getMilliSeconds()); return handled; }
void GHOST_System::dispatchEvents() { #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(); } m_timerManager->fireTimers(getMilliSeconds()); }
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, GHOST_GLSettings glSettings, const bool exclusive, const GHOST_TEmbedderWindowID parentWindow) { GHOST_WindowSDL *window = NULL; window = new GHOST_WindowSDL(this, title, left, top, width, height, state, parentWindow, type, ((glSettings.flags & GHOST_glStereoVisual) != 0), exclusive); if (window) { if (GHOST_kWindowStateFullScreen == state) { SDL_Window *sdl_win = window->getSDLWindow(); SDL_DisplayMode mode; static_cast<GHOST_DisplayManagerSDL *>(m_displayManager)->getCurrentDisplayModeSDL(mode); SDL_SetWindowDisplayMode(sdl_win, &mode); SDL_ShowWindow(sdl_win); SDL_SetWindowFullscreen(sdl_win, SDL_TRUE); } if (window->getValid()) { m_windowManager->addWindow(window); pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window)); } else { delete window; window = NULL; } } return window; }
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; }
bool GHOST_System::dispatchEvents() { bool handled = false; #ifdef WITH_INPUT_NDOF // NDOF Motion event is sent only once per dispatch, so do it now: if (m_ndofManager) { handled |= m_ndofManager->sendMotionEvent(); } #endif if (m_eventManager) { handled |= m_eventManager->dispatchEvents(); } m_timerManager->fireTimers(getMilliSeconds()); return handled; }
VOID TaskMgr::resumePausedTasks() { TaskList *pPausedTasks = getPausedTasks(); Time_t currTime = getMilliSeconds(); TaskListItr nextItr = pPausedTasks->begin(); while (nextItr != pPausedTasks->end()) { TaskListItr curItr = nextItr++; Task *pTask = *curItr; if (pTask->wake() <= currTime) { pTask->resumeTask(); } } }
RETVAL TrafficTask::run(VOID *arg) { LOG_ENTERFN(); BOOL abortTraffiTask = FALSE; LOG_DEBUG("Running TrafficTask, Session Rate [%d]", m_rate); Time_t currTime = getMilliSeconds(); m_lastRunTime = currTime; Counter numSession = Stats::getStats(GSIM_STAT_NUM_SESSIONS_CREATED); for (U32 i = 0; i < m_rate; i++) { GtpImsiKey imsiKey; MEMSET(&imsiKey, 0, sizeof(GtpImsiKey)); m_imsiGen.allocNew(&imsiKey); UeSession::createUeSession(imsiKey); numSession++; if ((0 != m_maxSessions) && (numSession >= m_maxSessions)) { LOG_DEBUG("Max Sessions = [%d] Created, Stopping Traffic",\ m_maxSessions); abortTraffiTask = TRUE; break; } } Display::displayStats(); if (abortTraffiTask) { stop(); } else { m_wakeTime = m_lastRunTime + m_ratePeriod; pause(); } LOG_EXITFN(ROK); }
VOID Display::disp() { static BOOL firTime = TRUE; CLEAR_SCREEN(); if (firTime) { firTime = FALSE; fprintf(stdout, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"\ "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); } PRINT_SEPERATOR(); fprintf(stdout, "Start: %s ", m_timeStr); Time_t runTime = (getMilliSeconds() / 1000) - m_startTime; fprintf(stdout, "Run-Time: %us ", (U32)runTime); fprintf(stdout, "Remote-Host: %s:%d \r\n", m_remIpAddrStr, m_remPort); Counter ssnCreated = getStats(GSIM_STAT_NUM_SESSIONS_CREATED); Counter ssnSucc = getStats(GSIM_STAT_NUM_SESSIONS_SUCC); Counter ssnFail = getStats(GSIM_STAT_NUM_SESSIONS_FAIL); fprintf(stdout, "Total-Sessions: %u \r\n", ssnCreated); fprintf(stdout, "Session-Completed: %u \r\n", ssnSucc); fprintf(stdout, "Session-Aborted: %u \r\n", ssnFail); PRINT_SEPERATOR(); fprintf(stdout," "\ "Messages Retrans Timeout Unexpected-Msg\r\n"); for (U32 i = 0; i < m_msgVecLen; i++) { MsgTask *pMsgTask = (*m_pMsgVec)[i]; fprintf(stdout, "%s ", pMsgTask->m_msgName); if (pMsgTask->type() == MSG_TASK_SEND) { fprintf(stdout, "\t--->"); fprintf(stdout, " \t%9d", pMsgTask->m_numSnd); fprintf(stdout, "%9d", pMsgTask->m_numSndRetrans); fprintf(stdout, " %9d", pMsgTask->m_numTimeOut); fprintf(stdout, ENDLINE); } else if (pMsgTask->type() == MSG_TASK_RECV) { fprintf(stdout, " \t<---"); fprintf(stdout, "\t%9d", pMsgTask->m_numRcv); fprintf(stdout, "%9d", pMsgTask->m_numRcvRetrans); fprintf(stdout, " %9d", pMsgTask->m_numUnexp); fprintf(stdout, ENDLINE); } else { fprintf(stdout, "[Wait %5d]\r\n", 0); fprintf(stdout, ENDLINE); } } PRINT_BLANK_LINE(); if (KB_KEY_PAUSE_TRAFFIC == Keyboard::key) { PRINT_END_SEPERATOR_RESUME(); } else { PRINT_END_SEPERATOR_PAUSE(); } fflush(stdout); }
bool GHOST_SystemWin32::processNDOF(RAWINPUT const& raw) { bool eventSent = false; GHOST_TUns64 now = getMilliSeconds(); static bool firstEvent = true; if (firstEvent) { // determine exactly which device is plugged in RID_DEVICE_INFO info; unsigned infoSize = sizeof(RID_DEVICE_INFO); info.cbSize = infoSize; GetRawInputDeviceInfo(raw.header.hDevice, RIDI_DEVICEINFO, &info, &infoSize); if (info.dwType == RIM_TYPEHID) m_ndofManager->setDevice(info.hid.dwVendorId, info.hid.dwProductId); else puts("<!> not a HID device... mouse/kb perhaps?"); firstEvent = false; } // The NDOF manager sends button changes immediately, and *pretends* to // send motion. Mark as 'sent' so motion will always get dispatched. eventSent = true; #if defined(_MSC_VER) || defined(FREE_WINDOWS64) // using Microsoft compiler & header files // they invented the RawInput API, so this version is (probably) correct. // MinGW64 also works fine with this BYTE const *data = raw.data.hid.bRawData; // struct RAWHID { // DWORD dwSizeHid; // DWORD dwCount; // BYTE bRawData[1]; // }; #else // MinGW's definition (below) doesn't agree, so we need a slight // workaround until it's fixed BYTE const *data = &raw.data.hid.bRawData; // struct RAWHID { // DWORD dwSizeHid; // DWORD dwCount; // BYTE bRawData; // <== isn't this s'posed to be a BYTE*? // }; #endif BYTE packetType = data[0]; switch (packetType) { case 1: // translation { short *axis = (short *)(data + 1); // massage into blender view coords (same goes for rotation) short t[3] = {axis[0], -axis[2], axis[1]}; m_ndofManager->updateTranslation(t, now); if (raw.data.hid.dwSizeHid == 13) { // this report also includes rotation short r[3] = {-axis[3], axis[5], -axis[4]}; m_ndofManager->updateRotation(r, now); // I've never gotten one of these, has anyone else? puts("ndof: combined T + R"); } break; } case 2: // rotation { short *axis = (short *)(data + 1); short r[3] = {-axis[0], axis[2], -axis[1]}; m_ndofManager->updateRotation(r, now); break; } case 3: // buttons { int button_bits; memcpy(&button_bits, data + 1, sizeof(button_bits)); m_ndofManager->updateButtons(button_bits, now); break; } } return eventSent; }
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; SDL_Window *sdl_win= SDL_GetWindowFromID(sdl_sub_evt.windowID); GHOST_WindowSDL *window= findGhostWindow(sdl_win); assert(window != NULL); int x_win, y_win; SDL_GetWindowPosition(sdl_win, &x_win, &y_win); GHOST_TInt32 x_root= sdl_sub_evt.x + x_win; GHOST_TInt32 y_root= sdl_sub_evt.y + y_win; #if 0 if(window->getCursorGrabMode() != GHOST_kGrabDisable && window->getCursorGrabMode() != GHOST_kGrabNormal) { GHOST_TInt32 x_new= x_root; GHOST_TInt32 y_new= y_root; GHOST_TInt32 x_accum, y_accum; GHOST_Rect bounds; /* fallback to window bounds */ if(window->getCursorGrabBounds(bounds)==GHOST_kFailure) window->getClientBounds(bounds); /* could also clamp to screen bounds * wrap with a window outside the view will fail atm */ bounds.wrapPoint(x_new, y_new, 8); /* offset of one incase blender is at screen bounds */ window->getCursorGrabAccum(x_accum, y_accum); // cant use setCursorPosition because the mouse may have no focus! if(x_new != x_root || y_new != y_root) { if (1 ) { //xme.time > m_last_warp) { /* when wrapping we don't need to add an event because the * setCursorPosition call will cause a new event after */ SDL_WarpMouseInWindow(sdl_win, x_new - x_win, y_new - y_win); /* wrap */ window->setCursorGrabAccum(x_accum + (x_root - x_new), y_accum + (y_root - y_new)); // m_last_warp= lastEventTime(xme.time); } else { // setCursorPosition(x_new, y_new); /* wrap but don't accumulate */ SDL_WarpMouseInWindow(sdl_win, x_new - x_win, y_new - y_win); } g_event = new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, x_new, y_new); } else { g_event = new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, x_root + x_accum, y_root + y_accum); } } else #endif { g_event= new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, x_root, y_root); } 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; SDL_Keycode sym= sdl_sub_evt.keysym.sym; 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 */ /* printf("%d\n", sym); */ if(sym > 127) { switch(sym) { case SDLK_KP_DIVIDE: sym= '/'; break; case SDLK_KP_MULTIPLY: sym= '*'; break; case SDLK_KP_MINUS: sym= '-'; break; case SDLK_KP_PLUS: sym= '+'; break; case SDLK_KP_1: sym= '1'; break; case SDLK_KP_2: sym= '2'; break; case SDLK_KP_3: sym= '3'; break; case SDLK_KP_4: sym= '4'; break; case SDLK_KP_5: sym= '5'; break; case SDLK_KP_6: sym= '6'; break; case SDLK_KP_7: sym= '7'; break; case SDLK_KP_8: sym= '8'; break; case SDLK_KP_9: sym= '9'; break; case SDLK_KP_0: sym= '0'; break; case SDLK_KP_PERIOD: sym= '.'; break; default: sym= 0; break; } } else { if(sdl_sub_evt.keysym.mod & (KMOD_LSHIFT|KMOD_RSHIFT)) { /* lame US keyboard assumptions */ if(sym >= 'a' && sym <= ('a' + 32)) { sym -= 32; } else { switch(sym) { case '`': sym= '~'; break; case '1': sym= '!'; break; case '2': sym= '@'; break; case '3': sym= '#'; break; case '4': sym= '$'; break; case '5': sym= '%'; break; case '6': sym= '^'; break; case '7': sym= '&'; break; case '8': sym= '*'; break; case '9': sym= '('; break; case '0': sym= ')'; break; case '-': sym= '_'; break; case '=': sym= '+'; break; case '[': sym= '{'; break; case ']': sym= '}'; break; case '\\': sym= '|'; break; case ';': sym= ':'; break; case '\'': sym= '"'; break; case ',': sym= '<'; break; case '.': sym= '>'; break; case '/': sym= '?'; break; default: break; } } } } g_event= new GHOST_EventKey(getMilliSeconds(), type, window, gkey, sym); } break; } if (g_event) { pushEvent(g_event); } }
bool GHOST_SystemCarbon::handleMouseDown(EventRef event) { WindowPtr window; short part; BitMap screenBits; bool handled = true; GHOST_WindowCarbon *ghostWindow; Point mousePos = {0, 0}; ::GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mousePos); part = ::FindWindow(mousePos, &window); ghostWindow = (GHOST_WindowCarbon *) ::GetWRefCon(window); switch (part) { case inMenuBar: handleMenuCommand(::MenuSelect(mousePos)); break; case inDrag: /* * The DragWindow() routine creates a lot of kEventWindowBoundsChanged * events. By setting m_ignoreWindowSizedMessages these are suppressed. * \see GHOST_SystemCarbon::handleWindowEvent(EventRef event) */ /* even worse: scale window also generates a load of events, and nothing * is handled (read: client's event proc called) until you release mouse (ton) */ GHOST_ASSERT(validWindow(ghostWindow), "GHOST_SystemCarbon::handleMouseDown: invalid window"); m_ignoreWindowSizedMessages = true; ::DragWindow(window, mousePos, &GetQDGlobalsScreenBits(&screenBits)->bounds); m_ignoreWindowSizedMessages = false; pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowMove, ghostWindow) ); break; case inContent: if (window != ::FrontWindow()) { ::SelectWindow(window); /* * We add a mouse down event on the newly actived window */ //GHOST_PRINT("GHOST_SystemCarbon::handleMouseDown(): adding mouse down event, " << ghostWindow << "\n"); EventMouseButton button; ::GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button); pushEvent(new GHOST_EventButton(getMilliSeconds(), GHOST_kEventButtonDown, ghostWindow, convertButton(button))); } else { handled = false; } break; case inGoAway: GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0"); if (::TrackGoAway(window, mousePos)) { // todo: add option-close, because it's in the HIG // if (event.modifiers & optionKey) { // Close the clean documents, others will be confirmed one by one. //} // else { pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowClose, ghostWindow)); //} } break; case inGrow: GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0"); ::ResizeWindow(window, mousePos, NULL, NULL); break; case inZoomIn: case inZoomOut: GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0"); if (::TrackBox(window, mousePos, part)) { int macState; macState = ghostWindow->getMac_windowState(); if (macState == 0) ::ZoomWindow(window, part, true); else if (macState == 2) { // always ok ::ZoomWindow(window, part, true); ghostWindow->setMac_windowState(1); } else { // need to force size again // GHOST_TUns32 scr_x,scr_y; /*unused*/ Rect outAvailableRect; ghostWindow->setMac_windowState(2); ::GetAvailableWindowPositioningBounds(GetMainDevice(), &outAvailableRect); //this->getMainDisplayDimensions(scr_x,scr_y); ::SizeWindow(window, outAvailableRect.right - outAvailableRect.left, outAvailableRect.bottom - outAvailableRect.top - 1, false); ::MoveWindow(window, outAvailableRect.left, outAvailableRect.top, true); } } break; default: handled = false; break; } return handled; }
OSStatus GHOST_SystemCarbon::handleKeyEvent(EventRef event) { OSStatus err = eventNotHandledErr; GHOST_IWindow *window = m_windowManager->getActiveWindow(); UInt32 kind = ::GetEventKind(event); UInt32 modifiers; UInt32 rawCode; GHOST_TKey key; unsigned char ascii; /* Can happen, very rarely - seems to only be when command-H makes * the window go away and we still get an HKey up. */ if (!window) { //::GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &rawCode); //key = convertKey(rawCode); return err; } err = noErr; switch (kind) { case kEventRawKeyDown: case kEventRawKeyRepeat: case kEventRawKeyUp: ::GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &rawCode); ::GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &ascii); key = convertKey(rawCode); ascii = convertRomanToLatin(ascii); // if (key!=GHOST_kKeyUnknown) { GHOST_TEventType type; if (kind == kEventRawKeyDown) { type = GHOST_kEventKeyDown; } else if (kind == kEventRawKeyRepeat) { type = GHOST_kEventKeyDown; /* XXX, fixme */ } else { type = GHOST_kEventKeyUp; } pushEvent(new GHOST_EventKey(getMilliSeconds(), type, window, key, ascii, NULL) ); // } break; case kEventRawKeyModifiersChanged: /* ugh */ ::GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); if ((modifiers & shiftKey) != (m_modifierMask & shiftKey)) { pushEvent(new GHOST_EventKey(getMilliSeconds(), (modifiers & shiftKey) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, GHOST_kKeyLeftShift) ); } if ((modifiers & controlKey) != (m_modifierMask & controlKey)) { pushEvent(new GHOST_EventKey(getMilliSeconds(), (modifiers & controlKey) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, GHOST_kKeyLeftControl) ); } if ((modifiers & optionKey) != (m_modifierMask & optionKey)) { pushEvent(new GHOST_EventKey(getMilliSeconds(), (modifiers & optionKey) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, GHOST_kKeyLeftAlt) ); } if ((modifiers & cmdKey) != (m_modifierMask & cmdKey)) { pushEvent(new GHOST_EventKey(getMilliSeconds(), (modifiers & cmdKey) ? GHOST_kEventKeyDown : GHOST_kEventKeyUp, window, GHOST_kKeyOS) ); } m_modifierMask = modifiers; break; default: err = eventNotHandledErr; break; } return err; }
OSStatus GHOST_SystemCarbon::handleMouseEvent(EventRef event) { OSStatus err = eventNotHandledErr; GHOST_IWindow *window = m_windowManager->getActiveWindow(); UInt32 kind = ::GetEventKind(event); switch (kind) { case kEventMouseDown: case kEventMouseUp: // Handle Mac application responsibilities if ((kind == kEventMouseDown) && handleMouseDown(event)) { err = noErr; } else { GHOST_TEventType type = (kind == kEventMouseDown) ? GHOST_kEventButtonDown : GHOST_kEventButtonUp; EventMouseButton button; /* Window still gets mouse up after command-H */ if (m_windowManager->getActiveWindow()) { // handle any tablet events that may have come with the mouse event (optional) handleTabletEvent(event); ::GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button); pushEvent(new GHOST_EventButton(getMilliSeconds(), type, window, convertButton(button))); err = noErr; } } break; case kEventMouseMoved: case kEventMouseDragged: { Point mousePos; if (window) { //handle any tablet events that may have come with the mouse event (optional) handleTabletEvent(event); ::GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mousePos); pushEvent(new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, mousePos.h, mousePos.v)); err = noErr; } break; } case kEventMouseWheelMoved: { OSStatus status; //UInt32 modifiers; EventMouseWheelAxis axis; SInt32 delta; //status = ::GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers); //GHOST_ASSERT(status == noErr, "GHOST_SystemCarbon::handleMouseEvent(): GetEventParameter() failed"); status = ::GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(axis), NULL, &axis); GHOST_ASSERT(status == noErr, "GHOST_SystemCarbon::handleMouseEvent(): GetEventParameter() failed"); if (axis == kEventMouseWheelAxisY) { status = ::GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(delta), NULL, &delta); GHOST_ASSERT(status == noErr, "GHOST_SystemCarbon::handleMouseEvent(): GetEventParameter() failed"); /* * Limit mouse wheel delta to plus and minus one. */ delta = delta > 0 ? 1 : -1; pushEvent(new GHOST_EventWheel(getMilliSeconds(), window, delta)); err = noErr; } } break; } return err; }
/* this is an old style low level event queue. * As we want to handle our own timers, this is ok. * the full screen hack should be removed */ bool GHOST_SystemCarbon::processEvents(bool waitForEvent) { bool anyProcessed = false; EventRef event; // SetMouseCoalescingEnabled(false, NULL); do { GHOST_TimerManager *timerMgr = getTimerManager(); if (waitForEvent) { GHOST_TUns64 next = timerMgr->nextFireTime(); double timeOut; if (next == GHOST_kFireTimeNever) { timeOut = kEventDurationForever; } else { timeOut = (double)(next - getMilliSeconds()) / 1000.0; if (timeOut < 0.0) timeOut = 0.0; } ::ReceiveNextEvent(0, NULL, timeOut, false, &event); } if (timerMgr->fireTimers(getMilliSeconds())) { anyProcessed = true; } if (getFullScreen()) { // Check if the full-screen window is dirty GHOST_IWindow *window = m_windowManager->getFullScreenWindow(); if (((GHOST_WindowCarbon *)window)->getFullScreenDirty()) { pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowUpdate, window) ); anyProcessed = true; } } /* end loop when no more events available */ while (::ReceiveNextEvent(0, NULL, 0, true, &event) == noErr) { OSStatus status = ::SendEventToEventTarget(event, ::GetEventDispatcherTarget()); if (status == noErr) { anyProcessed = true; } else { UInt32 i = ::GetEventClass(event); /* Ignore 'cgs ' class, no documentation on what they * are, but we get a lot of them */ if (i != 'cgs ') { if (i != 'tblt') { // tablet event. we use the one packaged in the mouse event ; //printf("Missed - Class: '%.4s', Kind: %d\n", &i, ::GetEventKind(event)); } } } ::ReleaseEvent(event); } } while (waitForEvent && !anyProcessed); return anyProcessed; }
double Timer::getSeconds() { return (getMilliSeconds() * 0.000001); }