Exemplo n.º 1
0
void EngineApp::OnUpdateGame( double fTime, float fElapsedTime )
   {
	if ( m_bQuitting )
	   {
      ENG_ASSERT( PushUserEvent( m_ShutDownEventType, 0 ) );
      }

	if ( m_pEngineLogic )
	   {
      IEventManager::GetSingleton()->VUpdate( 20 ); // allow event queue to process for up to 20 ms
		g_pApp->m_pEngineLogic->VOnUpdate( ( float ) fTime, fElapsedTime );
	   }
   }
Exemplo n.º 2
0
bool GUIChannel::process(SDL_Event * event)
{
	bool catched = false;

	if ( event->type == SDL_MOUSEBUTTONUP && event->button.button == 1 ) {
		mousedown = false;
		if ( selectBegin > -1 && test(event->button.x, event->button.y) ) {
			int tmp = event->button.y - 48;
			if ( tmp > y ) {
				selectEnd = (tmp-3)/8 - 2 + offset + 1;
			} else {
				selectEnd = selectBegin+1;
				selectBegin = (tmp-3)/8 - 2 + offset;
			}
			catched = true;
		}
	} else if ( event->type == SDL_MOUSEBUTTONDOWN ) {
		if ( event->button.button == 5 ) // wheel down : scroll down
			offset++;
		else if ( event->button.button == 4 ) // wheel up : scroll up
			offset--;
		else if ( event->button.button == 1 ) { // mouse click : select & edit
			if ( test(event->button.x, event->button.y) ) {
				y = event->button.y - 48;
				x = event->button.x - area.x;
				if ( y < 8 )
					selectBegin = EDITDUTY;
				else if ( y < 16 )
					selectBegin = EDITDEC;
				else if ( y > 21 )
					selectBegin = (y-3)/8 - 2 + offset;
				selectEnd = selectBegin + 1;
				mousedown = true;
			} else if ( selectBegin != -1 )
				selectBegin = -1;
		}
		catched = true;
	} else if ( event->type == SDL_MOUSEMOTION && mousedown
			&& selectBegin < -1 ) { // edit mode
		int dy = (event->motion.y-48) - y;
		if ( dy > DELTA || dy < -DELTA ) {
			if ( dy > DELTA )
				y += DELTA;
			else
				y -= DELTA;

			if ( selectBegin == EDITDUTY && number < 6 ) { // edit duty
				if ( dy > DELTA && channel->duty < 6 )
					channel->duty++;
				else if ( dy < -DELTA && channel->duty > 0 )
					channel->duty--;
				synth->setChannelDuty(number, channel->duty);
			} else if ( selectBegin == EDITDEC ) { // edit decrease rate
				if ( dy > DELTA && channel->dec < 99 )
					channel->dec++;
				else if ( dy < -DELTA && channel->dec > 0 )
					channel->dec--;
			}

			catched = true;
		}
	} else if ( event->type == SDL_KEYDOWN ) {
		if ( event->key.keysym.sym == SDLK_PAGEDOWN ) { // page down
			offset += 48;
			catched = true;
		} else if ( event->key.keysym.sym == SDLK_PAGEUP ) { // page up
			offset -= 48;
			catched = true;
		} else if ( selectBegin >= 0 ) {
			if ( event->key.keysym.sym == SDLK_DOWN ) { // move/select down
				if ( selectBegin < MAXROWS-1 && selectEnd < MAXROWS ) {
					if ( shift )
						selectEnd++;
					else {
						selectBegin++;
						selectEnd = selectBegin+1;
					}
					catched = true;
				}
				if ( selectEnd >= offset + 48 && selectEnd < MAXROWS )
					PushUserEvent(GUI_SETOFFSET, (void *)(offset+10));
			} else if ( event->key.keysym.sym == SDLK_UP ) { // move/select up
				if ( shift && selectBegin != selectEnd-1 ) {
					selectEnd--;
					catched = true;
				} else if ( selectBegin > 0 ) {
					selectBegin--;
					selectEnd = selectBegin+1;
					catched = true;
				}
				if ( selectEnd <= offset && selectBegin > 0 )
					PushUserEvent(GUI_SETOFFSET, (void *)(offset-10));
			} else if ( event->key.keysym.sym == SDLK_RETURN ) { // note on/off
				if ( selectBegin == selectEnd-1 ) {
					if ( channel->notes[selectBegin].active ) {
						lastNote = channel->notes[selectBegin];
						channel->deleteNote(selectBegin);
					} else {
						channel->setNote(selectBegin, lastNote);
					}
				} else {
					for ( int i = selectBegin ; i < selectEnd ; i++ )
						channel->deleteNote(i);
				}
				catched = true;
			} else if ( event->key.keysym.sym == SDLK_LEFT ) { // move left
				if ( number > 0 ) {
					PushUserEvent(GUI_SETCHANNEL,
							(void *)(number-1), (void *)selectBegin);
					selectBegin = -1;
					catched = true;
				}
			} else if ( event->key.keysym.sym == SDLK_RIGHT ) { // move right
				if ( number < 7 ) {
					PushUserEvent(GUI_SETCHANNEL,
							(void *)(number+1), (void *)selectBegin);
					selectBegin = -1;
					catched = true;
				}
			} else if ( event->key.keysym.sym == SDLK_d ) { // note -
				if ( selectBegin == selectEnd-1
						&& ! channel->notes[selectBegin].active ) {
					channel->setNote(selectBegin, lastNote);
				} else {
					for ( int i = selectBegin ; i < selectEnd ; i++ ) {
						if ( channel->notes[i].active
								&& channel->notes[i].note > 0 ) {
							channel->notes[i].note--;
							if ( i == selectBegin )
								lastNote = channel->notes[i];
						}
					}
				}
				catched = true;
			} else if ( event->key.keysym.sym == SDLK_g ) { // note +
				if ( selectBegin == selectEnd-1
						&& ! channel->notes[selectBegin].active ) {
					channel->setNote(selectBegin, lastNote);
				} else {
					for ( int i = selectBegin ; i < selectEnd ; i++ ) {
						if ( channel->notes[i].active
								&& channel->notes[i].note < 127 ) {
							channel->notes[i].note++;
							if ( i == selectBegin )
								lastNote = channel->notes[i];
						}
					}
				}
				catched = true;
			} else if ( event->key.keysym.sym == SDLK_e ) { // volume -
				if ( selectBegin == selectEnd-1
						&& ! channel->notes[selectBegin].active ) {
					channel->notes[selectBegin] = lastNote;
				} else {
					for ( int i = selectBegin ; i < selectEnd ; i++ ) {
						if ( channel->notes[i].active
								&& channel->notes[i].volume > 0 ) {
							channel->notes[i].volume--;
							if ( i == selectBegin )
								lastNote = channel->notes[i];
						}
					}
				}
				catched = true;
			} else if ( event->key.keysym.sym == SDLK_t ) { // volume +
				if ( selectBegin == selectEnd-1
						&& ! channel->notes[selectBegin].active ) {
					channel->notes[selectBegin] = lastNote;
				} else {
					for ( int i = selectBegin ; i < selectEnd ; i++ ) {
						if ( channel->notes[i].active
								&& channel->notes[i].volume < 31 ) {
							channel->notes[i].volume++;
							if ( i == selectBegin )
								lastNote = channel->notes[i];
						}
					}
				}
				catched = true;
			} else if ( event->key.keysym.sym == SDLK_RCTRL 
					|| event->key.keysym.sym == SDLK_LCTRL ) { // set cursor
				synth->setRow(selectBegin);
			} else if ( event->key.keysym.sym == SDLK_x ) { // cut
				copy->size = selectEnd - selectBegin;
				memcpy(copy->notes, & channel->notes[selectBegin],
						copy->size * sizeof(Note));
				for ( int i = selectBegin ; i < selectEnd ; i++ )
					channel->deleteNote(i);
				catched = true;
			} else if ( event->key.keysym.sym == SDLK_c ) { // copy
				copy->size = selectEnd - selectBegin;
				memcpy(copy->notes, & channel->notes[selectBegin],
						copy->size * sizeof(Note));
				catched = true;
			} else if ( event->key.keysym.sym == SDLK_v ) { // paste
				memcpy(& channel->notes[selectBegin], copy->notes,
						copy->size * sizeof(Note));
				if ( channel->lastRow < selectBegin + copy->size )
					channel->lastRow = selectBegin + copy->size;
				catched = true;
			} else if ( event->key.keysym.sym == SDLK_LSHIFT
					|| event->key.keysym.sym == SDLK_RSHIFT )
				shift = true;
		}
	} else if ( event->type == SDL_KEYUP ) {
		if ( event->key.keysym.sym == SDLK_LSHIFT
				|| event->key.keysym.sym == SDLK_RSHIFT )
			shift = false;
	} else if ( event->type == SDL_USEREVENT ) {
		if ( event->user.code == GUI_SETOFFSET ) {
			offset = (int) event->user.data1;
			catched = true;
		} else if ( event->user.code == GUI_SETCHANNEL ) {
			int n = (int) event->user.data1;
			int s = (int) event->user.data2;
			if ( selectBegin >= 0 && selectEnd == selectBegin+1 ) {
				if ( n != number ) {
					selectBegin = -1;
					catched = true;
				}
			} else if ( n == number ) {
				selectBegin = s;
				selectEnd = s+1;
				catched = true;
			}
		}
	}

	if ( catched ) {
		if ( offset < 0 )
			offset = 0;
		if ( offset >= MAXROWS - 48 )
			offset = MAXROWS - 48;
		update();
	}

	return catched;
}
Exemplo n.º 3
0
void EngineApp::MsgProc( void )
   {
   SDL_Event event;
   HumanView*  pHumanView;
   if( SDL_PollEvent( &event ) )
      {
      if( event.type == m_ShutDownEventType )
         {
         pHumanView = GetHumanView();
         if( pHumanView && pHumanView->HasModalWindow() )
            {
            // force the dialog to exit
            ENG_ASSERT( PushUserEvent( pHumanView->GetModalEventType(), g_QuitNoPrompt ) >= 0 );
            // force next dialog( if it exists ) to exit
            ENG_ASSERT( PushUserEvent( m_ShutDownEventType, 0 ) >= 0 );
            }
         else // this is triggered by last dialog event
            {
            OnClose();
            }
         return;
         }
      switch( event.type )
         {
         case SDL_WINDOWEVENT:
            break;
         case SDL_QUIT: // this case is triggered by hitting 'x' at the window
            if( m_bQuitRequested )
               {
               return;
               }

            m_bQuitRequested = true;
            pHumanView = GetHumanView();
            // remenber to process additional messagebox
            if ( pHumanView )
				   {
               if( pHumanView->Ask( QUESTION_QUIT_GAME ) == IDNO )
                  {
                  // We've cleared the dialog, Reset quit requested flag
					   m_bQuitRequested = false;
					   return; 
                  }
               else
                  {
                  PushUserEvent( m_ShutDownEventType, 0 );
                  }
			      }
            m_bQuitting = true;
            break;
         case SDL_DROPFILE:
            SetWindowFocus();
            m_pEngineLogic->VOnFileDrop( event.drop.file, GetMousePosition() );
            SDL_free( event.drop.file );    // Free dropped_filedir memory
            break;
         case SDL_MOUSEBUTTONDOWN:
         case SDL_KEYDOWN:
         case SDL_KEYUP:
         case SDL_TEXTEDITING:
         case SDL_TEXTINPUT:
         case SDL_KEYMAPCHANGED:
         case SDL_MOUSEMOTION:
         case SDL_MOUSEBUTTONUP:
         case SDL_MOUSEWHEEL:
         case SDL_JOYAXISMOTION:
         case SDL_JOYBALLMOTION:
         case SDL_JOYHATMOTION:
         case SDL_JOYBUTTONDOWN:
         case SDL_JOYBUTTONUP:
         case SDL_JOYDEVICEADDED:
         case SDL_JOYDEVICEREMOVED:
         case SDL_CONTROLLERAXISMOTION:
         case SDL_CONTROLLERBUTTONDOWN:
         case SDL_CONTROLLERBUTTONUP:
         case SDL_CONTROLLERDEVICEADDED:
         case SDL_CONTROLLERDEVICEREMOVED:
         case SDL_CONTROLLERDEVICEREMAPPED:
         m_pEngineLogic->VOnMsgProc( event );
         }
      
      }// If poll event exist
   }// Function MsgProc