BOOL PieMenu::handleHover(S32 x, S32 y, MASK mask) { // initialize pie scale factor for popup effect F32 factor = getScaleFactor(); // initially, the current segment is marked as invalid mCurrentSegment = -1; // remember to take the UI scaling into account LLVector2 scale = gViewerWindow->getDisplayScale(); // move mouse coordinates to be relative to the pie center LLVector2 mouseVector(x - PIE_OUTER_SIZE / scale.mV[VX], y - PIE_OUTER_SIZE / scale.mV[VY]); // get the distance from the center point F32 distance = mouseVector.length(); // check if our mouse pointer is within the pie slice area if (distance > PIE_INNER_SIZE && (distance < (PIE_OUTER_SIZE * factor) || mFirstClick)) { // get the angle of the mouse pointer from the center in radians F32 angle = acos(mouseVector.mV[VX] / distance); // if the mouse is below the middle of the pie, reverse the angle if (mouseVector.mV[VY] < 0) { angle = F_PI * 2 - angle; } // rotate the angle slightly so the slices' centers are aligned correctly angle += F_PI / 8; // calculate slice number from the angle mCurrentSegment = (S32) (8.f * angle / (F_PI * 2.f)) % 8; } return TRUE; }
void Asteroids::OnMouseDragged(int x, int y) { GLVector2i mouseVector(GLVector2i(x, mGameDisplay->GetHeight() - y)); // mSpaceship->Shoot(); // mGameWorld->AddObject(CreateAsteroid(x,y)); // mGameWorld->AddObject(CreateAsteroid()); // mAsteroidCount++; const int zl = mGameWindow->GetZoomLevel(); GLVector3f m2w((x - mGameDisplay->GetWidth()/2)/zl + mCameraFocus->x, (mGameDisplay->GetHeight()/2 - y)/zl + mCameraFocus->y, 0.0); mSelectionBox->SetMouse(GLVector2i(x,y)); mSelectionBox->SetWorldCoord1(m2w); // if(mMoveCamera) { // GLVector2i m = GLVector2i(x - mGameWorld->GetWidth(), (y - mGameWorld->GetHeight()) * -1); // float delta = sqrt(pow((m.x - mCameraFocus.x),2) * pow((m.y - mCameraFocus.y),2)); // delta = delta/10.0; //// mCameraFocus; // cout << "Delta : " << delta << endl; // cout << "Mouse Vector: " << m << endl; // mCameraFocus += m*delta; // } // cout << "Camera Focus: " << mCameraFocus << endl; // cout << endl; }
//Logica do movimento void Player::update() { Point mousePos = input->getMousePos(); Vector mouseVector(mousePos.getX() - pos.getX() + Game::getCurrentLevel()->getMap()->getXOffs(), mousePos.getY() - pos.getY() + Game::getCurrentLevel()->getMap()->getYOffs()); mouseVector = mouseVector.getNormalized(); angleDirection = atan2(mouseVector.getY(),mouseVector.getX()) - atan2(-1,0); if(input->isLeft()) { if(!collision(pos.getX() - speed,pos.getY())) { pos.setX(pos.getX() - speed); } } else if(input->isRight()) { if(!collision(pos.getX() + speed,pos.getY())) { pos.setX(pos.getX() + speed); } } if(input->isUp()) { if(!collision(pos.getX(),pos.getY() - speed)) { pos.setY(pos.getY() - speed); } } else if(input->isDown()) { if(!collision(pos.getX(),pos.getY() + speed)) { pos.setY(pos.getY() + speed); } } if(input->isMouseClicked() == 1 ) { Projectile* p = new Projectile(); if(weapon->shoot(p)) { int xx = pos.getX() + 20*sin(angleDirection); int yy = pos.getY() + 20*-cos(angleDirection); p->setOrigin(Point(xx,yy)); p->setAngle(angleDirection); std::cout<<"Angle: "<<angleDirection<<std::endl; Game::getCurrentLevel()->getProjectiles()->add(p); } } }
int gamePicture::updateRotation(POINT* p) { D3DXVECTOR3 mouseVector(p->x - position.x, p->y - position.y, 0); //define a vector that if(abs(mouseVector.x)>3&& abs(mouseVector.y)>3) { if(mouseVector.x >0) orient = atan(mouseVector.y/mouseVector.x)*180/3.1415; else orient = atan(mouseVector.y/mouseVector.x)*180/3.1415+180; vel.x = cos(orient*3.1415 / 180)*10; vel.y = sin(orient*3.1415 / 180)*10; } else { vel.x = 0; vel.y = 0; } return 0; }
void PieMenu::draw( void ) { // save the current OpenGL drawing matrix so we can freely modify it gGL.pushMatrix(); // save the widget's rectangle for later use LLRect r=getRect(); // initialize pie scale factor for popup effect F32 factor=1.0; #if PIE_POPUP_EFFECT // set the popup size if this was the first click on the menu if(mFirstClick) { factor=PIE_POPUP_FACTOR; } // otherwise check if the popup timer is still running else if(mPopupTimer.getStarted()) { // if the timer ran past the popup time, stop the timer and set the size to 1.0 F32 elapsedTime=mPopupTimer.getElapsedTimeF32(); if(elapsedTime>PIE_POPUP_TIME) { factor=1.0; mPopupTimer.stop(); } // otherwise calculate the size factor to make the menu shrink over time else { factor=PIE_POPUP_FACTOR-(PIE_POPUP_FACTOR-1.0)*elapsedTime/PIE_POPUP_TIME; } // setRect(r); // obsolete? } #endif #if PIE_DRAW_BOUNDING_BOX // draw a bounding box around the menu for debugging purposes gl_rect_2d(0,r.getHeight(),r.getWidth(),0,LLColor4(1,1,1,1),FALSE); #endif // set up pie menu colors LLColor4 lineColor=LLUIColorTable::instance().getColor("PieMenuLineColor"); LLColor4 selectedColor=LLUIColorTable::instance().getColor("PieMenuSelectedColor"); LLColor4 textColor=LLUIColorTable::instance().getColor("PieMenuTextColor"); LLColor4 bgColor=LLUIColorTable::instance().getColor("PieMenuBgColor"); LLColor4 borderColor=bgColor % (F32)0.3; // if the user wants their own colors, apply them here if(gSavedSettings.getBOOL("OverridePieColors")) { bgColor=LLUIColorTable::instance().getColor("PieMenuBgColorOverride") % gSavedSettings.getF32("PieMenuOpacity"); borderColor=bgColor % (1.f-gSavedSettings.getF32("PieMenuFade")); selectedColor=LLUIColorTable::instance().getColor("PieMenuSelectedColorOverride"); } // on first click, make the menu fade out to indicate "borderless" operation if(mFirstClick) borderColor%=0.0; // initially, the current segment is marked as invalid S32 currentSegment=-1; // get the current mouse pointer position local to the pie S32 x,y; LLUI::getMousePositionLocal(this,&x,&y); // remember to take the UI scaling into account LLVector2 scale=gViewerWindow->getDisplayScale(); // move mouse coordinates to be relative to the pie center LLVector2 mouseVector(x-PIE_OUTER_SIZE/scale.mV[VX],y-PIE_OUTER_SIZE/scale.mV[VY]); // get the distance from the center point F32 distance=mouseVector.length(); // check if our mouse pointer is within the pie slice area if(distance>PIE_INNER_SIZE && (distance<(PIE_OUTER_SIZE*factor) || mFirstClick)) { // get the angle of the mouse pointer from the center in radians F32 angle=acos(mouseVector.mV[VX]/distance); // if the mouse is below the middle of the pie, reverse the angle if(mouseVector.mV[VY]<0) angle=F_PI*2-angle; // rotate the angle slightly so the slices' centers are aligned correctly angle+=F_PI/8; // calculate slice number from the angle currentSegment=(S32) (8.0*angle/(F_PI*2.0)) % 8; } // move origin point to the center of our rectangle gGL.translatef(r.getWidth()/2,r.getHeight()/2,0.0); // draw the general pie background gl_washer_2d(PIE_OUTER_SIZE*factor,PIE_INNER_SIZE,32,bgColor,borderColor); // set up an item list iterator to point at the beginning of the item list slice_list_t::iterator cur_item_iter; cur_item_iter=mSlices->begin(); // clear current slice pointer mSlice=0; // current slice number is 0 S32 num=0; BOOL wasAutohide=FALSE; do { // standard item text color LLColor4 itemColor=textColor; // clear the label and set up the starting angle to draw in std::string label(""); F32 segmentStart=F_PI/4.0*(F32) num-F_PI/8.0; // iterate through the list of slices if(cur_item_iter!=mSlices->end()) { // get current slice item LLView* item=(*cur_item_iter); // check if this is a submenu or a normal click slice PieSlice* currentSlice=dynamic_cast<PieSlice*>(item); PieMenu* currentSubmenu=dynamic_cast<PieMenu*>(item); // advance internally to the next slice item cur_item_iter++; // in case it is regular click slice if(currentSlice) { // get the slice label and tell the slice to check if it's supposed to be visible label=currentSlice->getLabel(); currentSlice->updateVisible(); // disable it if it's not visible, pie slices never really disappear if(!currentSlice->getVisible()) { lldebugs << label << " is not visible" << llendl; currentSlice->setEnabled(FALSE); } // if the current slice is the start of an autohide chain, clear out previous chains if(currentSlice->getStartAutohide()) wasAutohide=FALSE; // check if the current slice is part of an autohide chain if(currentSlice->getAutohide()) { // if the previous item already won the autohide, skip this item if(wasAutohide) continue; // look at the next item in the pie LLView* lookAhead=(*cur_item_iter); // check if this is a normal click slice PieSlice* lookSlice=dynamic_cast<PieSlice*>(lookAhead); if(lookSlice) { // if the next item is part of the current autohide chain as well ... if(lookSlice->getAutohide() && !lookSlice->getStartAutohide()) { // ... it's visible and it's enabled, skip the current one. // the first visible and enabled item in autohide chains wins // this is useful for Sit/Stand toggles lookSlice->updateEnabled(); lookSlice->updateVisible(); if(lookSlice->getVisible() && lookSlice->getEnabled()) continue; // this item won the autohide contest wasAutohide=TRUE; } } } else // reset autohide chain wasAutohide=FALSE; // check if the slice is currently enabled currentSlice->updateEnabled(); if(!currentSlice->getEnabled()) { lldebugs << label << " is disabled" << llendl; // fade the item color alpha to mark the item as disabled itemColor%=(F32)0.3; } } // if it's a submenu just get the label else if(currentSubmenu) label=currentSubmenu->getLabel(); // if it's a slice or submenu, the mouse pointer is over the same segment as our counter and the item is enabled if((currentSlice || currentSubmenu) && (currentSegment==num) && item->getEnabled()) { // memorize the currently highlighted slice for later mSlice=item; // if we highlighted a different slice than before, we must play a sound if(mOldSlice!=mSlice) { // get the appropriate UI sound and play it char soundNum='0'+num; std::string soundName="UISndPieMenuSliceHighlight"; soundName+=soundNum; make_ui_sound(soundName.c_str()); // remember which slice we highlighted last, so we only play the sound once mOldSlice=mSlice; } // draw the currently highlighted pie slice gl_washer_segment_2d(PIE_OUTER_SIZE*factor,PIE_INNER_SIZE,segmentStart+0.02,segmentStart+F_PI/4.0-0.02,4,selectedColor,borderColor); } } // draw the divider line for this slice gl_washer_segment_2d(PIE_OUTER_SIZE*factor,PIE_INNER_SIZE,segmentStart-0.02,segmentStart+0.02,4,lineColor,borderColor); // draw the slice labels around the center mFont->renderUTF8(label, 0, PIE_X[num], PIE_Y[num], itemColor, LLFontGL::HCENTER, LLFontGL::VCENTER, LLFontGL::NORMAL, LLFontGL::DROP_SHADOW_SOFT); // next slice num++; } while(num<8); // do this until the menu is full // draw inner and outer circle, outer only if it was not the first click if(!mFirstClick) gl_washer_2d(PIE_OUTER_SIZE*factor,PIE_OUTER_SIZE*factor-2,32,lineColor,borderColor); gl_washer_2d(PIE_INNER_SIZE+1,PIE_INNER_SIZE-1,16,borderColor,lineColor); // restore OpenGL drawing matrix gGL.popMatrix(); // give control back to the UI library LLView::draw(); }
InputState WindowManager::SDLInput() { InputState input; while(SDL_PollEvent(&p_SDLEvent) != 0) { if( p_SDLEvent.type == SDL_QUIT ) { input.sdlInternalQuit = true; } else if(p_SDLEvent.key.keysym.sym == SDLK_ESCAPE) { input.esc = true; } else if(p_SDLEvent.type == SDL_WINDOWEVENT) { switch(p_SDLEvent.window.event) { case SDL_WINDOWEVENT_RESIZED: p_windowDimensions.w = p_SDLEvent.window.data1; p_windowDimensions.h = p_SDLEvent.window.data2; std::cout << "game lopp: new X: " << p_SDLEvent.window.data1 << "new Y: " << p_SDLEvent.window.data2 << std::endl; this->resizeGL(p_SDLEvent.window.data1, p_SDLEvent.window.data2); this->calculateProjections(); break; case SDL_WINDOWEVENT_MINIMIZED: Log::out("Window minimized: ", static_cast<int>(p_SDLEvent.window.windowID)); break; case SDL_WINDOWEVENT_RESTORED: Log::out("Window restored: ", static_cast<int>(p_SDLEvent.window.windowID)); break; case SDL_WINDOWEVENT_ENTER: Log::out("Mouse entered window: ", static_cast<int>(p_SDLEvent.window.windowID)); break; case SDL_WINDOWEVENT_LEAVE: Log::out("Mouse left window: ", static_cast<int>(p_SDLEvent.window.windowID)); break; case SDL_WINDOWEVENT_FOCUS_GAINED: SDL_Log("Window gained keyboard focus: ", static_cast<int>(p_SDLEvent.window.windowID)); break; case SDL_WINDOWEVENT_FOCUS_LOST: SDL_Log("Window lost keyboard focus: ", static_cast<int>(p_SDLEvent.window.windowID)); break; } } else if(p_SDLEvent.type == SDL_MOUSEMOTION) { SDL_GetMouseState(&p_mousePositionX, &p_mousePositionY); glm::vec2 mouseVector(p_mousePositionX, p_mousePositionY); this->normalizeInput(p_mousePositionX, p_mousePositionY); // p_camera->mouseUpdate(mouseVector); } if (p_SDLEvent.button.button == SDL_BUTTON_LEFT) { // SDL_GetMouseState(&p_mousePositionX, &p_mousePositionY); // glm::vec2 mouseVector(p_mousePositionX, p_mousePositionY); // this->normalizeInput(p_mousePositionX, p_mousePositionY); //map->locateCursor(p_mousePositionX, p_mousePositionY); } } if(p_SDLEvent.type == SDL_KEYDOWN) { switch(p_SDLEvent.key.keysym.sym) { case SDLK_SPACE: break; case SDLK_w: break; case SDLK_F1: SDL_ShowCursor(1); break; case SDLK_F2: SDL_ShowCursor(0); break; } } const Uint8 *state = SDL_GetKeyboardState(NULL); if (state[SDL_SCANCODE_W]) { //this->p_camera->processControls(DIRECTION::FORWARD); input.up = true; //this->p_camera->moveForward(); } if (state[SDL_SCANCODE_S]) { //this->p_camera->processControls(DIRECTION::BACKWARD); //this->p_camera->moveBackward(); input.down = true; } if (state[SDL_SCANCODE_A]) { //this->p_camera->processControls(DIRECTION::LEFT); input.left = true; //this->p_camera->strafeLeft(); } if (state[SDL_SCANCODE_D]) { //this->p_camera->processControls(DIRECTION::RIGHT); input.right = true; //this->p_camera->strafeRight(); } if (state[SDL_SCANCODE_Q]) { //this->p_camera->processControls(DIRECTION::UP); //this->p_camera->moveUp(); } if (state[SDL_SCANCODE_E]) { //this->p_camera->processControls(DIRECTION::DOWN); //this->p_camera->moveDown(); } if (state[SDL_SCANCODE_R]) { //this->fireBullet(); } if (state[SDL_SCANCODE_C]) { input.c = true; } if (state[SDL_SCANCODE_P]) { input.p = true; } if (state[SDL_SCANCODE_T]) { input.t = true; } if (state[SDL_SCANCODE_UP]) { input.up = true; } if (state[SDL_SCANCODE_DOWN]) { input.down = true; //camY -= 10; } if (state[SDL_SCANCODE_LEFT]) { input.left = true; //camX -= 10; } if (state[SDL_SCANCODE_RIGHT]) { input.right = true; //camX += 10; } return input; // for (auto iter = gameObjects.begin(); iter != gameObjects.end(); ++iter) // { // (*iter)->input(input); // } //this->player1->processInput(input); }
void QMapViewWidget::mouseMoveEvent(QMouseEvent *event) { switch (pMode) { case 0: { if (pSelectedItem >= -1) return; QRect rect = pBackBuffer.rect(); rect.moveCenter(QPoint(width()/2-1, height()/2-1)); if (rect.contains(event->pos())) { QPoint scenePos = event->pos() - rect.topLeft(); scenePos.setX(scenePos.x() / pRectSize); scenePos.setY(scenePos.y() / pRectSize); switch (pSelectedItem) { case -2: // ice if (!QChar(pMap[scenePos.y()][scenePos.x()]).isLetter()) pMap[scenePos.y()][scenePos.x()] = '.'; redrawMap(scenePos.y(),scenePos.x(), 1, 1); break; case -3: // wall pMap[scenePos.y()][scenePos.x()] = '#'; redrawMap(scenePos.y(),scenePos.x(), 1, 1); break; case -4: // red token case -5: // green token case -6: // blue token case -7: // red dest case -8: // green dest case -9: // blue dest pNewToken = scenePos; break; default: break; } update(); emit mapEdited(); } } break; case 1: { if (pIsAnimationRun) return; QRect rect = pBackBuffer.rect(); rect.moveCenter(QPoint(width()/2-1, height()/2-1)); QPoint tokenMousePoint(pSelToken.x()*24+ 12 + rect.left(), pSelToken.y()*24 + 12 + rect.top()); QLineF mouseVector(tokenMousePoint, event->pos()); pNewTokenType = (mouseVector.length() <= 12) ? 0 : pSelTokenType; if (pNewTokenType) calculateSelDirArrow(tokenMousePoint, mouseVector.angle()); else pSelDir = 0; update(); } break; default: break; } }