bool Director::mousePressed(ofPoint _mouse){ if (inside(_mouse)){ // Is over one dot? // bool overDot = false; for(int i=1;i<points.size()-1;i++){ ofPoint pos = toScreen(points[i]); if(pos.distance(_mouse)<20){ overDot = true; break; } } if (!overDot){ lastCLick = _mouse; } if(!ofGetKeyPressed() && !overDot){ float lenghtToClosest = 1000; int closest = -1; for (int i=0;i<points.size()-1;i++){ int next=i+1; ofVec2f AtoM = _mouse - toScreen(points[i]); ofVec2f AtoB = toScreen(points[next]) - toScreen(points[i]); float a = atan2f(AtoM.x, AtoM.y); float b = atan2f(AtoB.x, AtoB.y); if (abs(a - b) <= 0.05 && // 1. Is over the line AtoM.length() < lenghtToClosest && // 2. Is the closest one AtoM.length() < AtoB.length() ){ // 3. Is between those two points lenghtToClosest = AtoM.length(); closest = next; } } if(closest!=-1){ points.insert(points.begin()+closest, fromScreen(_mouse)); } } else if (ofGetKeyPressed('a') && !overDot){ points.insert(points.end()-1, fromScreen(_mouse)); } else if( ( ofGetKeyPressed('d') || ofGetKeyPressed(OF_KEY_BACKSPACE) || ofGetKeyPressed(OF_KEY_DEL) )&& overDot){ for(int i=1;i<points.size()-1;i++){ ofPoint pos = toScreen(points[i]); if(pos.distance(_mouse)<10){ points.erase(points.begin()+i); break; } } } } }
QUndoCommand* Navigator::mouseMoveEvent(QMouseEvent* e) { switch (m_currentAction) { case Rotation: { QPoint delta = e->pos() - m_lastMousePosition; rotate(m_renderer->scene().center(), delta.y(), delta.x(), 0); e->accept(); break; } case Translation: { Vector2f fromScreen(m_lastMousePosition.x(), m_lastMousePosition.y()); Vector2f toScreen(e->localPos().x(), e->localPos().y()); translate(m_renderer->scene().center(), fromScreen, toScreen); e->accept(); break; } case ZoomTilt: { QPoint delta = e->pos() - m_lastMousePosition; // Tilt rotate(m_renderer->scene().center(), 0, 0, delta.x()); // Zoom zoom(m_renderer->scene().center(), delta.y()); e->accept(); break; } default:; } m_lastMousePosition = e->pos(); if (e->isAccepted()) emit updateRequested(); return nullptr; }
// static void ScreenWakeLock::setKeepAwake(Screen& screen, bool keepAwake) { ScreenWakeLock* screenWakeLock = fromScreen(screen); if (!screenWakeLock) return; screenWakeLock->setKeepAwake(keepAwake); }
// static bool ScreenWakeLock::keepAwake(Screen& screen) { ScreenWakeLock* screenWakeLock = fromScreen(screen); if (!screenWakeLock) return false; return screenWakeLock->keepAwake(); }
QVector< Vector2f > EquirectangularProjector::groundPoly(SkyPoint* labelpoint, bool* drawLabel) const { float x0 = m_vp.width/2.; float y0 = m_vp.width/2.; if( m_vp.useAltAz ) { float dX = m_vp.zoomFactor*M_PI; float dY = m_vp.zoomFactor*M_PI; SkyPoint belowFocus; belowFocus.setAz( m_vp.focus->az().Degrees() ); belowFocus.setAlt( 0.0 ); Vector2f obf = toScreenVec( &belowFocus, false ); //If the horizon is off the bottom edge of the screen, //we can return immediately if ( obf.y() > m_vp.height ) { if( drawLabel ) *drawLabel = false; return QVector<Vector2f>(); } //We can also return if the horizon is off the top edge, //as long as the ground poly is not being drawn if ( obf.y() < 0. && m_vp.fillGround == false ) { if( drawLabel ) *drawLabel = false; return QVector<Vector2f>(); } QVector<Vector2f> ground; //Construct the ground polygon, which is a simple rectangle in this case ground << Vector2f( x0 - dX, obf.y() ) << Vector2f( x0 + dX, obf.y() ) << Vector2f( x0 + dX, y0 + dY ) << Vector2f( x0 - dX, y0 + dY ); if( labelpoint ) { QPointF pLabel( x0 -dX -50., obf.y() ); KStarsData *data = KStarsData::Instance(); *labelpoint = fromScreen(pLabel, data->lst(), data->geo()->lat()); } if( drawLabel ) *drawLabel = true; return ground; } else { float dX = m_vp.zoomFactor*M_PI/2; float dY = m_vp.zoomFactor*M_PI/2; QVector<Vector2f> ground; static const QString horizonLabel = i18n("Horizon"); float marginLeft, marginRight, marginTop, marginBot; SkyLabeler::Instance()->getMargins( horizonLabel, &marginLeft, &marginRight, &marginTop, &marginBot ); double daz = 90.; double faz = m_vp.focus->az().Degrees(); double az1 = faz -daz; double az2 = faz +daz; bool allGround = true; bool allSky = true; double inc = 1.0; //Add points along horizon for(double az = az1; az <= az2 + inc; az += inc) { SkyPoint p = pointAt(az); bool visible = false; Vector2f o = toScreenVec(&p, false, &visible); if( visible ) { ground.append( o ); //Set the label point if this point is onscreen if ( labelpoint && o.x() < marginRight && o.y() > marginTop && o.y() < marginBot ) *labelpoint = p; if ( o.y() > 0. ) allGround = false; if ( o.y() < m_vp.height ) allSky = false; } } if( allSky ) { if( drawLabel) *drawLabel = false; return QVector<Vector2f>(); } if( allGround ) { ground.clear(); ground.append( Vector2f( x0 - dX, y0 - dY ) ); ground.append( Vector2f( x0 + dX, y0 - dY ) ); ground.append( Vector2f( x0 + dX, y0 + dY ) ); ground.append( Vector2f( x0 - dX, y0 + dY ) ); if( drawLabel) *drawLabel = false; return ground; } if( labelpoint ) { QPointF pLabel( x0 -dX -50., ground.last().y() ); KStarsData *data = KStarsData::Instance(); *labelpoint = fromScreen(pLabel, data->lst(), data->geo()->lat()); } if( drawLabel ) *drawLabel = true; //Now add points along the ground ground.append( Vector2f( x0 + dX, ground.last().y() ) ); ground.append( Vector2f( x0 + dX, y0 + dY ) ); ground.append( Vector2f( x0 - dX, y0 + dY ) ); ground.append( Vector2f( x0 - dX, ground.first().y() ) ); return ground; } }
inline void Navigator::translate(const Vector3f &ref, float x, float y) { Vector2f fromScreen(0, 0); Vector2f toScreen(x, y); translate(ref, fromScreen, toScreen); }
bool Director::mouseDragged(ofPoint _mouse){ bool corners = false; ofPoint A = ofPoint(x,y); ofPoint B = ofPoint(x+width,y+height); if ( A.distance( _mouse) < 20 ){ ofPoint disp = ofPoint(_mouse.x - x, _mouse.y - y); x += disp.x; y += disp.y; width -= disp.x; height -= disp.y; this->set(x,y, width, height); corners = true; } else if ( B.distance( _mouse) < 20 ){ width += _mouse.x - x - width; height += _mouse.y - y - height; this->set(x,y, width, height); corners = true; } if(!corners){ if(inside(_mouse)){ // Is over one dot? // bool overDot = false; for(int i=1;i<points.size()-1;i++){ ofPoint pos = toScreen(points[i]); if(pos.distance(_mouse)<20){ overDot = true; break; } } if(!ofGetKeyPressed()&&overDot){ for(int i=0;i<points.size();i++){ ofPoint pos = toScreen(points[i]); if(pos.distance(_mouse)<10){ points[i] = fromScreen(_mouse); return true; } } } else if ( ofGetKeyPressed('a') && !overDot){ points.insert(points.end()-1, fromScreen(_mouse)); } else if ( ofGetKeyPressed('d') || ofGetKeyPressed(OF_KEY_BACKSPACE) || ofGetKeyPressed(OF_KEY_DEL) ){ for(int i=1;i<points.size()-1;i++){ ofPoint pos = toScreen(points[i]); if(pos.distance(_mouse)<10){ points.erase(points.begin()+i); return true; } } } else if(!overDot){ ofPoint diff = _mouse - lastCLick; x += diff.x; y += diff.y; lastCLick = _mouse; } } else { return false; } } else { return true; } }