void HelloPolycodeApp::handleEvent(Event *e) { if(e->getDispatcher() == core->getInput()) { InputEvent *inputEvent = (InputEvent*)e; switch(e->getEventCode()) { case InputEvent::EVENT_KEYDOWN: switch (inputEvent->keyCode()) { case KEY_r: vehicleController->warpVehicle(Vector3(6,1,5)); break; case KEY_UP: engineForce = -15; break; case KEY_DOWN: engineForce = 15; break; case KEY_LEFT: steeringValue = 0.5; break; case KEY_RIGHT: steeringValue = -0.5; break; case KEY_SPACE: breaking = true; break; } break; case InputEvent::EVENT_KEYUP: switch (inputEvent->key) { case KEY_UP: case KEY_DOWN: engineForce = 0; break; case KEY_LEFT: case KEY_RIGHT: steeringValue = 0.0; break; case KEY_SPACE: breaking = false; break; } break; } } }
void PolycodePlayer::handleEvent(Event *event) { if(event->getDispatcher() == debuggerTimer) { runFile(fullPath); debuggerTimer->Pause(true); } if(remoteDebuggerClient) { if(event->getDispatcher() == remoteDebuggerClient) { if(event->getEventCode() == Event::COMPLETE_EVENT) { dispatchEvent(new PolycodeDebugEvent(), PolycodeDebugEvent::EVENT_CLOSE); } } if(event->getDispatcher() == remoteDebuggerClient->client) { ClientEvent *clientEvent = (ClientEvent*) event; switch(event->getEventCode()) { case ClientEvent::EVENT_CLIENT_READY: debuggerTimer->Pause(true); runFile(fullPath); break; case ClientEvent::EVENT_SERVER_DATA: { switch(clientEvent->dataType) { case PolycodeRemoteDebuggerClient::EVENT_INJECT_CODE: { char *code = (char*) clientEvent->data; injectCodeString = String(code); doCodeInject = true; } break; } } break; } } } if(event->getDispatcher() == core) { switch(event->getEventCode()) { case Core::EVENT_CORE_RESIZE: PolycodeDebugEvent *event = new PolycodeDebugEvent(); event->xRes = core->getXRes(); event->yRes = core->getYRes(); dispatchEvent(event, PolycodeDebugEvent::EVENT_RESIZE); break; } } if(event->getDispatcher() == core->getInput()) { InputEvent *inputEvent = (InputEvent*) event; switch(event->getEventCode()) { case InputEvent::EVENT_KEYDOWN: { if(L && !crashed) { lua_getfield(L, LUA_GLOBALSINDEX, "onKeyDown"); lua_pushinteger(L, inputEvent->keyCode()); lua_pcall(L, 1,0,errH); } } break; case InputEvent::EVENT_KEYUP: { if(L && !crashed) { lua_getfield(L, LUA_GLOBALSINDEX, "onKeyUp"); lua_pushinteger(L, inputEvent->keyCode()); lua_pcall(L, 1,0,errH); } } break; case InputEvent::EVENT_MOUSEDOWN: { if(L && !crashed) { lua_getfield(L, LUA_GLOBALSINDEX, "onMouseDown"); lua_pushinteger(L, inputEvent->mouseButton); lua_pushnumber(L, inputEvent->mousePosition.x); lua_pushnumber(L, inputEvent->mousePosition.y); lua_pcall(L, 3,0,errH); } } break; case InputEvent::EVENT_MOUSEUP: { if(L && !crashed) { lua_getfield(L, LUA_GLOBALSINDEX, "onMouseUp"); lua_pushinteger(L, inputEvent->mouseButton); lua_pushnumber(L, inputEvent->mousePosition.x); lua_pushnumber(L, inputEvent->mousePosition.y); lua_pcall(L, 3,0,errH); } } break; case InputEvent::EVENT_MOUSEMOVE: { if(L && !crashed) { lua_getfield(L, LUA_GLOBALSINDEX, "onMouseMove"); lua_pushnumber(L, inputEvent->mousePosition.x); lua_pushnumber(L, inputEvent->mousePosition.y); lua_pcall(L, 2,0,errH); } } break; } } }
void HelloPolycodeApp::handleEvent(Event *event) { if(event->getDispatcher() == core->getInput()) { InputEvent *inputEvent = (InputEvent*)event; switch(event->getEventCode()) { case InputEvent::EVENT_KEYDOWN: switch (inputEvent->keyCode()) { case KEY_ESCAPE: client->Disconnect(); break; case KEY_UP: clientData.thrusting = 1; break; case KEY_LEFT: clientData.turning_state = TURNING_LEFT; break; case KEY_RIGHT: clientData.turning_state = TURNING_RIGHT; break; } break; case InputEvent::EVENT_KEYUP: switch (inputEvent->key) { case KEY_UP: clientData.thrusting = 0; break; case KEY_LEFT: case KEY_RIGHT: clientData.turning_state = NOT_TURNING; break; } break; } } if(event->getDispatcher() == client) { ClientEvent *clientEvent = (ClientEvent*) event; switch(clientEvent->getEventCode()) { case ClientEvent::EVENT_CLIENT_READY: Logger::log("Connected to server with client ID: %d!\n", client->getClientID()); break; case ClientEvent::EVENT_SERVER_DISCONNECTED: core->Shutdown(); break; case ClientEvent::EVENT_SERVER_DATA: { switch(clientEvent->dataType) { case PACKET_TYPE_SERVER_DATA: { ServerState *serverState = (ServerState*) clientEvent->data; for(int i=0; i < players.size(); i++) { ClientPlayer *clientPlayer = players[i]; for(int j=0; j < MAX_PLAYERS; j++) { if(clientPlayer->clientID == serverState->players[j].clientID && serverState->players[j].state != 0) { clientPlayer->playerEntity->setPosition(serverState->players[j].posX, serverState->players[j].posY); clientPlayer->playerEntity->setRotation(serverState->players[j].angle); } } } } break; case PLAYER_JOIN: { ServerClientInfo *newClientInfo = (ServerClientInfo*) clientEvent->data; createClientPlayer(newClientInfo->clientID); } break; case SERVER_INFO: { ServerInfo *info = (ServerInfo*) clientEvent->data; motdLabel->setText(info->motd); ServerState *serverState = &info->initialServerState; // create initial players for(int j=0; j < MAX_PLAYERS; j++) { if(serverState->players[j].state != 0) { createClientPlayer(serverState->players[j].clientID); } } client->sendReliableDataToServer(NULL, 0, CLIENT_READY); } break; } } break; } } }
void PolycodeIDEApp::handleEvent(Event *event) { if(event->getDispatcher() == frame->assetImporterWindow) { refreshProject(); } if(event->getDispatcher() == projectManager && event->getEventCode() == Event::CHANGE_EVENT) { if(projectManager->getActiveProject()) { if(frame->getCurrentProjectBrowser()) { frame->getCurrentProjectBrowser()->removeAllHandlersForListener(this); } PolycodeProjectFrame *projectFame = frame->getProjectFrame(projectManager->getActiveProject()); if(projectFame) { frame->switchToProjectFrame(projectFame); } else { frame->createProjectFrame(projectManager->getActiveProject()); } frame->getCurrentProjectBrowser()->addEventListener(this, Event::CHANGE_EVENT); frame->getCurrentProjectBrowser()->addEventListener(this, PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND); } } if(event->getDispatcher() == frame) { if(event->getEventCode() == Event::CHANGE_EVENT) { if(frame->getCurrentProjectBrowser()) { frame->getCurrentProjectBrowser()->removeAllHandlersForListener(this); } frame->getCurrentProjectBrowser()->addEventListener(this, Event::CHANGE_EVENT); frame->getCurrentProjectBrowser()->addEventListener(this, PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND); } if(event->getEventCode() == UIEvent::CLOSE_EVENT) { closeFile(); } } if(event->getDispatcher() == frame->fileDialog) { if(event->getEventCode() == UIEvent::OK_EVENT && event->getEventType() == "UIEvent") { String path = frame->fileDialog->getSelection(); if(path != "") { if(frame->fileDialog->action == "openProject") { PolycodeProject *project = projectManager->openProject(path); if(project) { projectManager->setActiveProject(project); } } else if(frame->fileDialog->action == "addFiles") { OSFileEntry entry = OSFileEntry(path, OSFileEntry::TYPE_FILE); core->copyDiskItem(path, projectManager->activeFolder + "/" + entry.name); refreshProject(); } else if(frame->fileDialog->action == "openImportAssets") { frame->assetImporterWindow->setSourceFileAndTargetFolder(path, projectManager->activeFolder, projectManager->activeFolder.replace(projectManager->getActiveProject()->getRootFolder(), "")); frame->showModal(frame->assetImporterWindow); frame->assetImporterWindow->addEventListener(this, UIEvent::OK_EVENT); } } } } if(event->getDispatcher() == menuBar) { String action = menuBar->getSelectedItem(); if(action == "new_file") { newFile(); } else if(action == "new_project") { newProject(); } else if(action == "new_folder") { newGroup(); } else if(action == "open_project") { openProject(); } else if(action == "close_project") { closeProject(); } else if(action == "close_file") { closeFile(); } else if(action == "remove_file") { removeFile(); } else if(action == "refresh_project") { refreshProject(); } else if(action == "save_file") { saveFile(); } else if(action == "browse_examples") { browseExamples(); } else if(action == "quit") { core->Shutdown(); } else if(action == "run_project") { runProject(); } else if(action == "export_project") { exportProject(); } else if(action == "show_api") { openDocs(); } else if(action == "show_about") { showAbout(); } else if(action == "toggle_console") { toggleConsole(); } else if(action == "settings") { showSettings(); } else if(action == "find") { findText(); } } if(event->getDispatcher() == frame->console->backtraceWindow) { if(event->getEventType() == "BackTraceEvent" && event->getEventCode() == BackTraceEvent::EVENT_BACKTRACE_SELECTED) { BackTraceEvent *btEvent = (BackTraceEvent*) event; openFileInProject(btEvent->project, btEvent->fileName); PolycodeEditor *editor = editorManager->getCurrentEditor(); if(editor) { if(editor->getEditorType() == "PolycodeTextEditor") { PolycodeTextEditor *textEditor = (PolycodeTextEditor*) editor; textEditor->highlightLine(btEvent->lineNumber); } } } } if(event->getDispatcher() == core) { switch(event->getEventCode()) { case Core::EVENT_LOST_FOCUS: core->setFramerate(3); break; case Core::EVENT_GAINED_FOCUS: core->setFramerate(60); break; case Core::EVENT_CORE_RESIZE: if(menuBar) { frame->Resize(core->getXRes(), core->getYRes()-25); menuBar->Resize(core->getXRes(), 25); } else { frame->Resize(core->getXRes(), core->getYRes()); } break; } } if(event->getDispatcher() == frame->getCurrentProjectBrowser()) { if(event->getEventType() == "PolycodeProjectBrowserEvent") { switch(event->getEventCode()) { case PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND: PolycodeProjectBrowserEvent *bEvent = (PolycodeProjectBrowserEvent*) event; if(bEvent->command == "add_new_file") { newFile(); } else if(bEvent->command == "add_files") { addFiles(); } else if(bEvent->command == "import_assets") { importAssets(); } else if(bEvent->command == "add_new_project") { newProject(); } else if(bEvent->command == "add_new_folder") { newGroup(); } else if(bEvent->command == "refresh") { refreshProject(); } else if(bEvent->command == "rename") { renameFile(); } else if(bEvent->command == "remove") { removeFile(); } break; } } if(event->getEventCode() == Event::CHANGE_EVENT) { PolycodeProjectBrowser *pb = frame->getCurrentProjectBrowser(); BrowserUserData *selectedData = pb->getSelectedData(); if(selectedData->type == 0) { projectManager->activeFolder = selectedData->parentProject->getRootFolder(); projectManager->selectedFile = ""; } else { projectManager->selectedFileEntry = selectedData->fileEntry; projectManager->selectedFile = selectedData->fileEntry.fullPath; if(selectedData->fileEntry.type == OSFileEntry::TYPE_FILE) { projectManager->activeFolder = selectedData->fileEntry.basePath; } else { projectManager->activeFolder = selectedData->fileEntry.fullPath; } } if(selectedData->type == 0) return; // don't open the editor if the selection was made by UITreeContainer arrow-key navigation if (selectedData && pb->treeContainer->getRootNode()->getSelectedNode()->isSelectedByKey() == false) { openFile(selectedData->fileEntry); } } } if(event->getDispatcher() == frame->playButton) { if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) { willRunProject = true; } } if(event->getDispatcher() == frame->stopButton) { if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) { stopProject(); } } if(event->getDispatcher() == frame->yesNoCancelPopup) { if(frame->yesNoCancelPopup->action == "closeFile") { switch(event->getEventCode()) { case UIEvent::YES_EVENT: { PolycodeEditor *editor = editorManager->getCurrentEditor(); if(editor) { editor->saveFile(); closeFile(); } frame->yesNoCancelPopup->action = ""; frame->hideModal(); } break; case UIEvent::NO_EVENT: { PolycodeEditor *editor = editorManager->getCurrentEditor(); if(editor) { editor->setHasChanges(false); closeFile(); } frame->yesNoCancelPopup->action = ""; frame->hideModal(); } break; case UIEvent::CANCEL_EVENT: break; } } else if(frame->yesNoCancelPopup->action == "closeQuitFile") { switch(event->getEventCode()) { case UIEvent::YES_EVENT: { PolycodeEditor *editor = editorManager->getCurrentEditor(); if(editor) { editor->saveFile(); closeFile(); if(editorManager->openEditors.size() > 0) { editorManager->setCurrentEditor(editorManager->openEditors[0]); } else{ editorManager->setCurrentEditor(NULL); } } frame->yesNoCancelPopup->action = ""; frame->hideModal(); if(quitApp()) { core->Shutdown(); } } break; case UIEvent::NO_EVENT: { PolycodeEditor *editor = editorManager->getCurrentEditor(); if(editor) { editor->setHasChanges(false); closeFile(); if(editorManager->openEditors.size() > 0) { editorManager->setCurrentEditor(editorManager->openEditors[0]); } else{ editorManager->setCurrentEditor(NULL); } } frame->yesNoCancelPopup->action = ""; frame->hideModal(); if(quitApp()) { core->Shutdown(); } } break; case UIEvent::CANCEL_EVENT: quittingApp = false; break; } } else if (frame->yesNoCancelPopup->action == "closeProject") { switch (event->getEventCode()) { case UIEvent::YES_EVENT: saveFiles(tempEditorStore); doCloseProject(); break; case UIEvent::NO_EVENT: doCloseProject(); break; case UIEvent::CANCEL_EVENT: break; } frame->yesNoCancelPopup->action = ""; frame->hideModal(); } else if (frame->yesNoCancelPopup->action == "closeFiles") { switch (event->getEventCode()) { case UIEvent::YES_EVENT: saveFiles(tempEditorStore); doCloseFiles(tempEditorStore); break; case UIEvent::NO_EVENT: doCloseFiles(tempEditorStore); break; case UIEvent::CANCEL_EVENT: break; } frame->yesNoCancelPopup->action = ""; frame->hideModal(); } } else if(event->getDispatcher() == frame->yesNoPopup) { if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CANCEL_EVENT) { if(frame->yesNoPopup->action == "saveAndRun") { runNextFrame = true; } frame->hideModal(); frame->yesNoPopup->action = ""; } if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) { if(frame->yesNoPopup->action == "removeFile") { doRemoveFile(); } if(frame->yesNoPopup->action == "saveAndRun") { editorManager->saveFilesForProject(projectManager->getActiveProject()); runNextFrame = true; } frame->hideModal(); frame->yesNoPopup->action = ""; } } if(event->getDispatcher() == frame->textInputPopup) { if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) { if(frame->textInputPopup->action == "newGroup") { core->createFolder(projectManager->activeFolder+"/"+frame->textInputPopup->getValue()); if(projectManager->getActiveProject()) { refreshProject(); } } if(frame->textInputPopup->action == "renameFile") { core->moveDiskItem(projectManager->selectedFileEntry.fullPath, projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue()); if(projectManager->getActiveProject()) { refreshProject(); } PolycodeEditor *editor = editorManager->getEditorForPath(projectManager->selectedFileEntry.fullPath); if(editor) { editor->setFilePath(projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue()); } projectManager->selectedFileEntry.fullPath = projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue(); projectManager->selectedFileEntry.name = frame->textInputPopup->getValue(); } frame->hideModal(); } } if(event->getDispatcher() == frame->settingsWindow) { if(event->getEventType() == "UIEvent") { Config *config = CoreServices::getInstance()->getConfig(); SettingsWindow *settingsWindow = frame->settingsWindow; if(event->getEventCode() == UIEvent::OK_EVENT) { config->setStringValue("Polycode", "useExternalTextEditor", settingsWindow->useExternalTextEditorBox->isChecked() ? "true" : "false"); config->setStringValue("Polycode", "externalTextEditorCommand", settingsWindow->externalTextEditorCommand->getText()); config->setStringValue("Polycode", "uiTheme", settingsWindow->uiThemeBox->getSelectedItem()->label); if(settingsWindow->textureFilteringBox->getSelectedIndex() == 0) { config->setStringValue("Polycode", "textureFilteringMode", "linear"); } else { config->setStringValue("Polycode", "textureFilteringMode", "nearest"); } frame->hideModal(); } } } if(event->getDispatcher() == frame->exportProjectWindow) { if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) { projectManager->exportProject(projectManager->getActiveProject(), frame->exportProjectWindow->projectLocationInput->getText(), frame->exportProjectWindow->macCheckBox->isChecked(), frame->exportProjectWindow->winCheckBox->isChecked(), frame->exportProjectWindow->linCheckBox->isChecked(), frame->exportProjectWindow->compileCheckBox->isChecked()); frame->hideModal(); } } if(event->getDispatcher() == frame->newProjectWindow) { if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) { projectManager->createNewProject(frame->newProjectWindow->getTemplateFolder(), frame->newProjectWindow->getProjectName(), frame->newProjectWindow->getProjectLocation()); frame->hideModal(); } } if(event->getDispatcher() == frame->newFileWindow) { if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) { projectManager->createNewFile(frame->newFileWindow->getTemplatePath(), frame->newFileWindow->getFileName()); frame->hideModal(); if(projectManager->getActiveProject()) { refreshProject(); } } } if(event->getDispatcher() == frame->exampleBrowserWindow) { if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) { String fullPath = String(core->getDefaultWorkingDirectory()+"/"+frame->exampleBrowserWindow->getExamplePath()); PolycodeProject* project = projectManager->openProject(fullPath); OSFileEntry projectEntry = OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE); projectManager->setActiveProject(project); frame->hideModal(); } } // close files and editors after the close file button is pressed /* if (event->getDispatcher() == frame->closeFileButton) { if (event->getEventCode() == UIEvent::CLICK_EVENT) { if (core->getInput()->getKeyState(KEY_RSHIFT) || core->getInput()->getKeyState(KEY_LSHIFT)) closeFiles(editorManager->openEditors); else closeFile(); } } */ // open an editor/file if project browser has focus and user hits enter or right-arrow key if (event->getDispatcher() == CoreServices::getInstance()->getCore()->getInput()) { if(frame->getActiveProjectFrame()) { if (event->getEventCode() == InputEvent::EVENT_KEYDOWN && frame->getCurrentProjectBrowser()->treeContainer->hasFocus) { InputEvent *inEvent = (InputEvent*)event; if (inEvent->keyCode() == KEY_RETURN || inEvent->keyCode() == KEY_RIGHT) { BrowserUserData *selectedData = frame->getCurrentProjectBrowser()->getSelectedData(); if (selectedData) openFile(selectedData->fileEntry); } } } } }
void manual_thrusters_test_app::handleEvent(Event *e) { if(e->getDispatcher() == core->getInput()) { InputEvent *inputEvent = (InputEvent*)e; switch(e->getEventCode()) { case InputEvent::EVENT_KEYDOWN: switch (inputEvent->keyCode()) { case KEY_0: case KEY_1: case KEY_2: case KEY_3: case KEY_4: case KEY_5: case KEY_6: case KEY_7: case KEY_8: case KEY_9: { size_t t_index = inputEvent->keyCode() - KEY_0; if(t_index < thruster_cfg.thrusters.size()) { thruster_sys[t_index].t.engage(); } } break; case KEY_SPACE: { linearSpeed = Vector3(0, 0, 0); rotationSpeed = 0; } break; } break; case InputEvent::EVENT_KEYUP: switch (inputEvent->key) { case KEY_0: case KEY_1: case KEY_2: case KEY_3: case KEY_4: case KEY_5: case KEY_6: case KEY_7: case KEY_8: case KEY_9: { size_t t_index = inputEvent->keyCode() - KEY_0; if(t_index < thruster_cfg.thrusters.size()) { thruster_sys[t_index].t.disengage(); } } break; } break; } } }
void App::handleEvent(Event *e) { // Handle the input if (e->getDispatcher() == core->getInput()) { InputEvent* inputEvent = (InputEvent*)e; if (e->getEventCode() == InputEvent::EVENT_MOUSEWHEEL_UP) { // Zoomin by 10% this->camOffset.x -= this->camOffset.x * 0.1; if (this->camOffset.x < 0) this->camOffset.x = 0; } else if (e->getEventCode() == InputEvent::EVENT_MOUSEWHEEL_DOWN) { // Zoomout by 10% this->camOffset.x += this->camOffset.x * 0.1; } else if (e->getEventCode() == InputEvent::EVENT_KEYDOWN) { if (inputEvent->keyCode() == KEY_LEFT) { // Cycle to the left int index = universe->entities().indexOf(this->viewTarget); int size = universe->entities().size(); if (index == 0) index = size - 1; else index -= 1; this->viewTarget = universe->entities().at(index); } else if (inputEvent->keyCode() == KEY_RIGHT) { // Cycle to the right int index = universe->entities().indexOf(this->viewTarget); int size = universe->entities().size(); if (index == size - 1) index = 0; else index += 1; this->viewTarget = universe->entities().at(index); } else if (inputEvent->keyCode() == KEY_UP) { // Increase time simulated if (deltaIndex < DELTA_SIZE - 1) deltaIndex++; this->universe->setDeltaTime(this->deltaTimes[this->deltaIndex]); } else if (inputEvent->keyCode() == KEY_DOWN) { // Decrease time simulated if (deltaIndex > 0) this->deltaIndex--; this->universe->setDeltaTime(this->deltaTimes[this->deltaIndex]); } } else if (e->getEventCode() == InputEvent::EVENT_MOUSEDOWN) { // Right mouse button is held if (inputEvent->getMouseButton() == CoreInput::MOUSE_BUTTON2) this->mouseDown = true; } else if (e->getEventCode() == InputEvent::EVENT_MOUSEUP) { // Right mouse button is no longer held if (inputEvent->getMouseButton() == CoreInput::MOUSE_BUTTON2) this->mouseDown = false; } else if (e->getEventCode() == InputEvent::EVENT_MOUSEMOVE) { // Move the camera offset if (this->mouseDown) { Vector2 delta = this->core->getInput()->getMouseDelta(); this->camOffset.y += -1 * PI * delta.y * 0.001; this->camOffset.z += -1 * PI * delta.x * 0.001; // Clamp theta to [0,PI] if (this->camOffset.y > PI) this->camOffset.y = PI; else if (this->camOffset.y < 0) this->camOffset.y = 0; // Allow phi to wrap around from [0,2*PI] if (this->camOffset.z < 0) this->camOffset.z = 2 * PI; else if (this->camOffset.z > 2 * PI) this->camOffset.z = 0; } } } }
void CurrentApp::handleEvent(Event *e) { static int camnum = 1; if(e -> getDispatcher() == core->getInput()) { InputEvent * inputEvent = (InputEvent*)e; switch(e->getEventCode()) { case InputEvent::EVENT_KEYDOWN: switch(inputEvent->keyCode()) { case 27: // ESCAPE exit(0); break; case KEY_UP: keyboard.setKey(KEY_UP, true); break; case KEY_DOWN: keyboard.setKey(KEY_DOWN, true); break; case KEY_LEFT: keyboard.setKey(KEY_LEFT, true); break; case KEY_RIGHT: keyboard.setKey(KEY_RIGHT, true); break; case 306: // Left Control keyboard.setKey(306, true); break; case 304: // Left Shift keyboard.setKey(304, true); break; case 49: // 1 if (camnum == 1 ) break; camnum = 1; scene->getDefaultCamera()->setPosition(Vector3(1,2,17)); player.dirtyCam = true; break; case 50: // 2 if (camnum == 2 ) break; camnum = 2; scene->getDefaultCamera()->setPosition(Vector3(15,15,17)); player.dirtyCam = true; break; default: //std::cout<<"KEY "<<inputEvent->keyCode()<<std::endl; break; } break; case InputEvent::EVENT_KEYUP: switch(inputEvent->keyCode()) { case KEY_UP: keyboard.setKey(KEY_UP, false); break; case KEY_DOWN: keyboard.setKey(KEY_DOWN, false); break; case KEY_LEFT: keyboard.setKey(KEY_LEFT, false); break; case KEY_RIGHT: keyboard.setKey(KEY_RIGHT, false); break; case 306: // Left Control keyboard.setKey(306, false); break; case 304: // Left Shift keyboard.setKey(304, false); break; default: break; } break; default: break; } } }